django 1.5.1
我创建自定义身份验证模型:
文件api / models.py
from django.contrib.auth.models import BaseUserManager, AbstractUser
class User(AbstractUser):
token = models.CharField(max_length=64, null=False, blank=False, help_text=_('Photo for carte'), unique=True)
updated_token = models.DateTimeField(auto_now_add=True, help_text=_('Create record'))
USERNAME_FIELD = 'email'
objects = MyUserManager()
def __unicode__(self):
return "пользователь: %s" % self.email
class Meta:
app_label = 'custom_auth'
file settings.py
AUTH_USER_MODEL = 'custom_auth.User'
.....
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
.....
'south',
'django.contrib.admin',
)
on ./manage.py syncdb我收到错误:
admin.logentry: 'user' has a relation with model <class 'api.models.User'>, which has either not been installed or is abstract.
如何判断这个问题?
修改1 试过评论行并制作syncdb:
'django.contrib.admin',
syncdb成功了 之后尝试在./manage.py shell中创建用户
In [1]: from api.models import User
In [2]: User.objects.create_superuser('test@test.com', 'test')
并收到错误:
DatabaseError: (1146, "Table 'app_name.custom_auth_user' doesn't exist")
答案 0 :(得分:1)
您需要在班级app_label
上设置INSTALLED_APPS
:app_label = 'api'
:设置'custom_auth'
(默认设置),或将INSTALLED_APPS
添加到{ {1}}(当然,它必须是一个有效的应用程序)。
Django中的验证过程尝试使用get_model
获取新的User类,默认情况下get_model
仅返回已安装应用的模型。您可以使用当前代码进行验证:
>>> loading.get_model('custom_auth', 'user')
>>> loading.get_model('custom_auth', 'user', only_installed=False)
> api.models.User
答案 1 :(得分:0)
您忘记将Meta app_label说明添加到INSTALLED_APPS:
# Application definition
INSTALLED_APPS = (
...
'custom_auth',
)