我有一个旧项目,其中有一个默认创建的用户模型。
接下来,我们被要求更改默认用户模型。
我们将用户模型重新定义为:
class Staff(AbstractUser):
# ... new fields ...
# no need in model
user_permissions = None
groups = None
class Meta(AbstractUser.Meta):
db_table = 'auth_user'
swappable = "AUTH_USER_MODEL"
接下来,我们将其添加到settings.py文件中:
# user model
AUTH_USER_MODEL = 'test.Staff'
# django authentication backend
AUTHENTICATION_BACKENDS = [
# 'django.contrib.auth.backends.ModelBackend', # Django's default authentication backend
'test.backends.ModelBackend', # Custom authentication backend
]
必要的行,我们无法开始迁移(只需重新运行进行测试)。
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'test.staff', but app 'test' doesn't provide model 'staff'
请告诉我如何在django中正确替换用户。