django.db.utils.OperationalError: 没有这样的表: auth_user

安装后 Django-userena 一个错误
my django version: 1.9.5
我只是在安装 django-userena 一步一步,但是当我携带它时,发生错误,我不知道如何解决它。


Traceback /most recent call last/:
File "manage.py", line 12, in <module>
execute_from_command_line/sys.argv/
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute//
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command/subcommand/.run_from_argv/self.argv/
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute/*args, **cmd_options/
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle/*args, **options/
File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
emit_post_migrate_signal/self.verbosity, self.interactive, connection.alias/
File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 50, in emit_post_migrate_signal
using=db/
File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py", line 192, in send
response = receiver/signal=self, sender=sender, **named/
File "C:\Python27\lib\site-packages\guardian\management\__init__.py", line 33, in create_anonymous_user
User.objects.get/**lookup/
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 122, in manager_method
return getattr/self.get_queryset//, name//*args, **kwargs/
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 381, in get
num = len/clone/
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 240, in __len__
self._fetch_all//
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 1074, in _fetch_all
self._result_cache = list/self.iterator///
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 52, in __iter__
results = compiler.execute_sql//
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 848, in execute_sql
cursor.execute/sql, params/
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super/CursorDebugWrapper, self/.execute/sql, params/
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute/sql, params/
File "C:\Python27\lib\site-packages\django\db\utils.py", line 95, in __exit__
six.reraise/dj_exc_type, dj_exc_value, traceback/
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute/sql, params/
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py", line 323, in execute
return Database.Cursor.execute/self, query, params/
django.db.utils.OperationalError: no such table: auth_user


应用程序:


INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',

'userena',
'guardian',
'easy_thumbnails',
'accounts',
]


</module>
已邀请:

三叔

赞同来自:

./manage.py migrate


如果您的版本 Django 平等的 1.9 或更低,使用


./manage.py syncdb


然后


python manage.py createsuperuser


更多信息
https://github.com/django/djan ... ms.py
也许它会有所帮助

莫问

赞同来自:

问题在于这一行:


File "C:\Python27\lib\site-packages\guardian\management\__init__.py", line 33, in create_anonymous_user
User.objects.get/**lookup/



guardian\management\__init__.py

is calling
User

before it is defined.

Why is it called before it is defined?
...well, it is called by
makemigrations

to find out if there are changes in the
db

to define them /the changes that are found/

...so this is a "chicken and egg" problem.

I have the same error with a similar problem but the offending code was my own code /not a library like
guardian

/

My code was like this:


CHAT_BOT_USER, created = User.objects.get_or_create/username='rosty', \ email=settings.EMAIL_HOST_USER/


进攻部分是
User

, 在创建表之前使用
auth_user


只有在存在表时才能运行代码解决了问题。 它不会发生
OperationError

. 你可以学习它
try/except

, 像这样:


from django.db import OperationalError

try:
CHAT_BOT_USER, created = User.objects.get_or_create/username='rosty', email=settings.EMAIL_HOST_USER/

except OperationalError:
CHAT_BOT_USER = None

if created:
CHAT_BOT_USER.set_password/settings.EMAIL_HOST_PASSWORD/
CHAT_BOT_USER.save//


因此,
makemigrations

运行代码
except

, 和
runserver

- 代码
try

.

注意逻辑价值
created

, 您可以使用任何其他方法来避免执行代码。
makemigration

, 这取决于结果
User.objects....

詹大官人

赞同来自:

我得到了同样的错误并解决了同样的事情,我检查了上述表是否存在于错误中 connected DB 或不。 但这不是。 再次应用迁移,并运作。


python manage.py migrate

python manage.py makemigrations

董宝中

赞同来自:

跑: python3 manage.py migrate

要回复问题请先登录注册