所以我一直在使用这个网站:
构建我的项目的一部分,但我不断收到错误
ValueError: The field admin.LogEntry.user was declared with a lazy reference
to 'polls.user', but app 'polls' doesn't provide model 'user'.
The field calendarium.Event.created_by was declared with a lazy reference to
'polls.user', but app 'polls' doesn't provide model 'user'.
The field calendarium.Occurrence.created_by was declared with a lazy
reference to 'polls.user', but app 'polls' doesn't provide model 'user'.
The field filer.Clipboard.user was declared with a lazy reference to
'polls.user', but app 'polls' doesn't provide model 'user'.
The field filer.File.owner was declared with a lazy reference to
'polls.user', but app 'polls' doesn't provide model 'user'.
The field filer.Folder.owner was declared with a lazy reference to
'polls.user', but app 'polls' doesn't provide model 'user'.
The field filer.FolderPermission.user was declared with a lazy reference to
'polls.user', but app 'polls' doesn't provide model 'user'.
The field polls.UserProfile.user was declared with a lazy reference to
'polls.user', but app 'polls' doesn't provide model 'user'.
我的应用名称称为民意调查,我已确保在我的设置中安装了“民意调查”并
AUTH_USER_MODEL = 'polls.User'
告诉Django这是我想要使用的模型。我的models.py也是这样的
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.db import models
from django.utils.translation import ugettext_lazy as _
class UserManager(BaseUserManager):
"""Define a model manager for User model with no username field."""
use_in_migrations = True
def _create_user(self, email, password, **extra_fields):
"""Create and save a User with the given email and password."""
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password=None, **extra_fields):
"""Create and save a regular User with the given email and
password."""
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
"""Create and save a SuperUser with the given email and password."""
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self._create_user(email, password, **extra_fields)
class User(AbstractUser):
"""User model."""
username = None
email = models.EmailField(_('email address'), unique=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = UserManager()
任何人都可以澄清为什么会这样吗?并提供解决方案?谢谢
答案 0 :(得分:1)
您的应用名称似乎是polls.User
,大写字母为U.但您在应用calenderium
模型Event
字段created_by
中对此模型的引用为{{1小u。我无法使用您提供的信息重新创建问题,所以请您尝试修复并回复给我?