应用名称为“后端”
Models.py
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
fb_userid = models.CharField(max_length=256)
Settings.py
AUTH_USER_MODEL = 'backend.User'
INSTALLED_APPS = [
'backend.apps.BackendConfig',
'rest_framework',
'rest_framework.authtoken',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'oauth2_provider',
'bffcode',
]
错误:
ERRORS:
backend.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'.
backend.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'.
bffcode.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'.
bffcode.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'.
我正在尝试在项目中替换用户模型,但无法创建迁移
答案 0 :(得分:0)
我同意Daniel不导入用户,但是即使您要更改为自定义用户模型的中间项目,由于Django的可互换模型的动态依赖项功能的局限性,仍然存在后果
AUTH_USER_MODEL引用的模型必须在其应用程序的首次迁移中创建(通常称为0001_initial);否则,您将遇到依赖性问题。