Django错误:关系" users_user"不存在

时间:2015-04-16 10:36:34

标签: python django

我在迁移过程中遇到以下错误:

  

django.db.utils.ProgrammingError:关系“users_user”不存在

  File "/Users/user/Documents/workspace/api/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/user/Documents/workspace/api/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/user/Documents/workspace/api/env/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/user/Documents/workspace/api/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)

这是我的模特:

from django.db import models
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from ..managers.user import UserManager


class User(AbstractBaseUser, PermissionsMixin):
    # Email identifier, primary key, unique identifier for the user.
    email = models.EmailField(verbose_name='email address', max_length=254, unique=True, db_index=True)
    is_admin = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    class Meta:
        verbose_name = 'User'
        app_label = "users"

    def __unicode__(self):
        return self.email

    @property
    def get_full_name(self):
        return self.email

    @property
    def get_short_name(self):
        return self.email

    def has_module_perms(self, app_label):
        """
        Does the user have permissions to view the app `app_label`
        """
        # Simplest possible answer: Yes, always
        return True

    @property
    def is_staff(self):
        # Simplest possible answer: All admins are staff
        return self.is_admin

设定:

AUTH_USER_MODEL = 'users.User'

我错过了什么?

3 个答案:

答案 0 :(得分:26)

在您的用户应用中,您应该有一个文件夹migrations。它应该只包含0001_initial.py__init__.py。这是对的吗?

尝试运行./manage.py sqlmigrate user 0001_initial并查看其功能,因为错误来自

答案 1 :(得分:0)

另一个问题还可能是您正在将数据库用于另一个应用程序。因此,在这种情况下,只需在重新进行迁移之前先删除数据库

答案 2 :(得分:0)

我遇到了同样的问题,我所做的就是运行python manage.py makemigrations <app_name>,并且不要忘记在您的<app_name>文件中的INSTALLED_APPS中添加settings.py