Python Django 错误:关系“users_user”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29672190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django error: relation "users_user" does not exist
提问by Prometheus
I'm getting the following error during migration:
我在迁移过程中收到以下错误:
django.db.utils.ProgrammingError: relation "users_user" does not exist
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)
This is my model:
这是我的模型:
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
Settings:
设置:
AUTH_USER_MODEL = 'users.User'
Anything I have missed?
我错过了什么吗?
采纳答案by tgdn
Inside your user app, you should have a folder migrations
. It should only contain 0001_initial.py
and __init__.py
. Is that correct?
在您的用户应用程序中,您应该有一个文件夹migrations
。它应该只包含0001_initial.py
和__init__.py
。那是对的吗?
Try running ./manage.py sqlmigrate user 0001_initial
and see what it does, because thats where the error comes from
尝试运行./manage.py sqlmigrate user 0001_initial
看看它做了什么,因为那是错误的来源
回答by Kelvin Onkundi
Another issue can also be the fact that you were using the database for another application. So if this can be the case just drop the database before making migrations again
另一个问题也可能是您将数据库用于另一个应用程序。因此,如果是这种情况,请在再次迁移之前删除数据库