在创建一个项目,然后是一个应用程序并将这个应用程序添加到我的INSTALLED_APPS
之后,我尝试通过AbstractUser
在我的子类中创建一个自定义用户类models.py
:
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
pass
然后我尝试运行makemigrations
并收到此错误:
SystemCheckError: System check identified some issues:
ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'CustomUser.groups'.
HINT: Add or change a related_name argument to the definition for 'User.groups' or 'CustomUser.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for 'User.user_permissions' clashes with reverse accessor for 'CustomUser.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'User.user_permissions' or 'CustomUser.user_permissions'.
main.CustomUser.groups: (fields.E304) Reverse accessor for 'CustomUser.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for 'CustomUser.groups' or 'User.groups'.
main.CustomUser.user_permissions: (fields.E304) Reverse accessor for 'CustomUser.user_permissions' clashes with reverse accessor for 'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for 'CustomUser.user_permissions' or 'User.user_permissions'.
添加AUTH_USER_MODEL = 'main.CustomUser'
(main
是我的应用程序)似乎解决了这个问题(makemigrations
成功,就像migrate
),但我不明白为什么我会得到这个错误,即使我只是定义了这个子类而没有实际使用它。
我想首先了解为什么会出现这个问题,以及添加如何AUTH_USER_MODEL
解决它。CustomUser
我真的不明白为什么我的和之间看起来有冲突auth.User
。