Python Django 1.8 LookupError身份验证用户模型

Python Django 1.8 LookupError身份验证用户模型,python,django,django-models,django-authentication,django-1.8,Python,Django,Django Models,Django Authentication,Django 1.8,我在我的应用程序中使用了一个名为foll的custon用户模型。 当我运行syncdb或makemigrations或migrate时,我会得到一个LookupError。请帮忙 在settings.py中,我将AUTH\u USER\u MODEL定义为'foll.USER' foll/models.py from django.db import models from django.contrib.auth.models import AbstractBaseUser, P

我在我的应用程序中使用了一个名为
foll
的custon用户模型。 当我运行
syncdb
makemigrations
migrate
时,我会得到一个
LookupError
。请帮忙

settings.py
中,我将
AUTH\u USER\u MODEL
定义为
'foll.USER'

foll/models.py

    from django.db import models
    from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
    from django.utils import timezone
    from django.core.mail import send_mail
    from django.utils.translation import ugettext_lazy as _

class UserManager(BaseUserManager):
    def create_user(self, email, password=None):
        """
        Creates and saves a User with the given email, date of
        birth and password.
        """
        if not email:
            raise ValueError('Users must have an email address')

        user = self.model(
            email=self.normalize_email(email),
        )

        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email, password):
        """
        Creates and saves a superuser with the given email, date of
        birth and password.
        """
        user = self.create_user(email,
                                password=password,
                                )
        user.is_admin = True
        user.save(using=self._db)
        return user


class User(AbstractBaseUser, PermissionsMixin):
    """
    Custom user class.
    """
    email = models.EmailField(_('email address'), unique=True, db_index=True)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    is_staff = models.BooleanField(_('staff status'), default=False)
    date_joined = models.DateTimeField(default=timezone.now)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    is_festival = models.BooleanField(default=True)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    def __unicode__(self):
        return self.email

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')
        abstract = True

    def get_full_name(self):
        """
        Returns the first_name plus the last_name, with a space in between.
        """
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        """
        Returns the short name for the user.
        """
        return self.first_name

    def email_user(self, subject, message, from_email=None, **kwargs):
        """
        Sends an email to this User.
        """
        send_mail(subject, message, from_email, [self.email], **kwargs)

    @property
    def is_festival(self):
        """Is the user a member of staff?"""
        return self.is_festival
当我运行
syncdb
makemigrations
时,我得到一个
LookupError

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/core/management/base.py", line 440, in execute
    self.check()
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/core/management/base.py", line 478, in check
    include_deployment_checks=include_deployment_checks,
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/contrib/auth/checks.py", line 12, in check_user_model
    cls = apps.get_model(settings.AUTH_USER_MODEL)
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/apps/registry.py", line 202, in get_model
    return self.get_app_config(app_label).get_model(model_name.lower())
  File "/Users/Blu/projects/fowl/env/lib/python2.7/site-packages/django/apps/config.py", line 162, in get_model
    "App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'fowl' doesn't have a 'user' model.
回溯(最近一次呼叫最后一次):
文件“manage.py”,第10行,在
从命令行(sys.argv)执行命令
文件“/Users/Blu/projects/foll/env/lib/python2.7/site packages/django/core/management/_init__uuuuuu.py”,第338行,从命令行执行
utility.execute()
文件“/Users/Blu/projects/foll/env/lib/python2.7/site-packages/django/core/management/_-init___.py”,第330行,执行
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/Users/Blu/projects/foll/env/lib/python2.7/site-packages/django/core/management/base.py”,第390行,运行时从
self.execute(*args,**cmd_选项)
文件“/Users/Blu/projects/foll/env/lib/python2.7/site packages/django/core/management/base.py”,第440行,在execute中
self.check()
文件“/Users/Blu/projects/foll/env/lib/python2.7/site packages/django/core/management/base.py”,第478行,选中
包括部署检查=包括部署检查,
文件“/Users/Blu/projects/foll/env/lib/python2.7/site packages/django/core/checks/registry.py”,第72行,运行检查
新建错误=检查(应用程序配置=应用程序配置)
文件“/Users/Blu/projects/foll/env/lib/python2.7/site packages/django/contrib/auth/checks.py”,check\u user\u模型第12行
cls=apps.get\u model(settings.AUTH\u USER\u model)
get_模型中的文件“/Users/Blu/projects/foll/env/lib/python2.7/site packages/django/apps/registry.py”,第202行
返回self.get\u app\u config(app\u标签)。get\u model(model\u name.lower())
get_模型中的文件“/Users/Blu/projects/foll/env/lib/python2.7/site packages/django/apps/config.py”,第162行
应用程序“%s”没有“%s”模型。“%(self.label,模型名称))
LookupError:应用程序“Foll”没有“用户”模型。

我做错了什么?

在您的
User
类的
Meta
中,您设置了导致问题的
abstract=True
。删除它,然后运行
makemigrations

另外,请注意,您正在重复中已经存在的许多字段。你可以消除它们

class User(AbstractBaseUser, PermissionsMixin):
    is_admin = models.BooleanField(default=False)
    is_festival = models.BooleanField(default=True)

    #The properties, methods, etc.. 

你运行过
manage.py migrate
?问得好,还有,别忘了
manage.py makemigrations
@Eva611是的。我还是一样error@nir谢谢我运行了这两个程序,得到了相同的
LookupError
。如果我尝试将它们添加到admin.py,我会得到一个
django.core.exceptions.impropertlyconfigured:模型用户是抽象的,因此无法向admin注册。
在您的
类Meta中
-您有
抽象=真
。删除它,然后运行makemigrations