[Django]-Migrating from auth.User to custom user model. Groups and permissions are always empty

0👍

I don’t have enough reputation to comment, but if it’s a one-time migration, I’d recommend doing a json dump of your auth.group and auth.permission models:

./manage.py dumpdata --indent=2 auth.group auth.permission > groups_and_perms.json

Then you can load them in again with:

./manage.py loaddata groups_and_perms.json

Also, groups and permissions would be ManyToMany relations, wouldn’t they be? If that’s the case, try using .save_m2m() in your copy_old_users() function:

custom_user.save()

custom_user.groups.add(*user.groups.all())
custom_user.user_permissions.add(*user.user_permissions.all())

custom_user.save_m2m()
👤Franey

Leave a comment