切换到Django自定义用户模型,组和权限

时间:2022-06-29 19:22:04

I updated my django 1.4 application with user profiles to use 1.5 Custom User Model.

我使用用户配置文件更新了我的django 1.4应用程序,以使用1.5自定义用户模型。

#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 schema migrations for south and all data was imported successfully.

我为南方编写了模式迁移,并且所有数据都已成功导入。

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

否则,我的auth_group和auth_permision有问题。 Django无法生成任何其他表,但是当我想获取权限或组时,我将此SQL与JOIN连接到其他表:

 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

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

1 个解决方案

#1


0  

You have not created appropriate table in the database. Make tables before switching 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 custom migration script for you user data, or you'll lose it.

然后为您的用户数据编写自定义迁移脚本,否则您将丢失它。

Look this manual and this documentation, it'll help you to understend what should be done.

查看本手册和本文档,它将帮助您了解应该做什么。

#1


0  

You have not created appropriate table in the database. Make tables before switching 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 custom migration script for you user data, or you'll lose it.

然后为您的用户数据编写自定义迁移脚本,否则您将丢失它。

Look this manual and this documentation, it'll help you to understend what should be done.

查看本手册和本文档,它将帮助您了解应该做什么。