【发布时间】:2013-12-23 07:35:06
【问题描述】:
我正在尝试使用其他字段和功能扩展默认 Django 的身份验证模型,因此我决定只扩展 User 模型并编写自己的身份验证后端。
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
class MyUser(User):
access_key = models.CharField(_('Acces Key'), max_length=64)
这确实是一个基本代码,但在尝试同步数据库时,我遇到了一个 Google 不知道的奇怪错误:
CommandError: One or more models did not validate:
core.sldcuser: 'user_ptr' defines a relation with the model 'auth.User', which has been swapped out. Update the relation to point at settings.AUTH_USER_MODEL.
在我的 settings.py 中,我添加了我认为需要的内容:
AUTH_USER_MODEL = 'core.MyUser'
有没有人偶然发现这个错误?
或者我应该使用一对一的方式,或者 1t1 与代理的混合?
【问题讨论】:
-
这里确定它是一个应用程序的核心是什么?
-
您不应该扩展
AbstractUser或AbstractBaseUser,因为这些是带有abstract = True的模型吗? -
我什至不知道这些课程,所以不确定。
标签: django django-models django-authentication