Go to Django user model, groups and permissions

I updated the django 1.4 application with user profiles to use the 1.5 user model of the user.

#core/models.py from django.contrib.auth.models import User, UserManager, BaseUserManager, AbstractUser class MyUserManager(BaseUserManager): pass class MyUser(AbstractUser): phone = models.CharField(blank = True, max_length = 18) completed_step = models.IntegerField(default = 0) objects = MyUserManager() 

I wrote a schema migration for the south, and all the data was successfully imported.

Otherwise, I have a problem with auth_group and auth_permision. Django cannot generate additional tables, but when I want to get permissions or groups, I have this SQL with JOIN for the additional table:

  SELECT ... FROM "core_myuser" WHERE "core_myuser"."id" = 61 (8ms) Found 1 matching rows SELECT ... FROM "core_myuser" WHERE "core_myuser"."id" = 363 (1ms) Found 1 matching rows SELECT ... FROM "auth_group" INNER JOIN "core_myuser_groups" ON ("auth_group"."id" = "core_myuser_groups"."group_id") WHERE "core_myuser_groups"."myuser_id" = 363 

With internal server error

http://cl.ly/image/0W1G3F2S3f3X

+4
source share
1 answer

You have not created the corresponding table in the database. Make tables before switching the user model:

 python manage.py syncdb #or if you're use south python manage.py schemamigration core --initial python manage.py migrate core 

Then write a custom migration script for user data, or you will lose it.

Check out this guide and this documentation to help you understand what needs to be done.

0
source

Source: https://habr.com/ru/post/1493143/


All Articles