After I install Django-userena,there is an error my django version :1.9.5 I just install django-userena step by step ,but when i migrate it ,an error happend and I don't how to solve it.
在安装了django-userena之后,我的django版本出现了一个错误: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
apps:
应用程序:
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',
]
2 个解决方案
#1
1
The problem is this line:
问题是这条线:
File "C:\Python27\lib\site-packages\guardian\management\__init__.py", line 33, in create_anonymous_user User.objects.get(**lookup)
文件“C:\ Python27 \ lib \ \ __init__卫报网站\ \管理。py",第33行,在create_signatous_user .objects.get(**查找)中
guardian\management\__init__.py
is calling User
before it is defined.
卫报\ \ __init__管理。py在定义用户之前调用它。
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)
为什么它在定义之前被调用?…好吧,这是通过mak移民来了解数据库中是否有变化来定义它们(发现的变化)
...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
)
我也有同样的问题,但违规的代码是我自己的代码(不是像guardian这样的库)
My code was like this:
我的代码是这样的:
CHAT_BOT_USER, created = User.objects.get_or_create(username='rosty', \ email=settings.EMAIL_HOST_USER)
CHAT_BOT_USER,= User.objects创建。get_or_create(用户名= ' rosty \电子邮件= settings.EMAIL_HOST_USER)
The offending part is the User
being used before the auth_user
table is created
违规部分是在创建auth_user表之前使用的用户
I solved by only executing the code when the table is present. This happens when there is no OperationError
. And you can know it with a try/except
like this:
我只在表存在时才执行代码。这发生在没有操作错误时。你只要试一试就知道了/除了:
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()
This way makemigrations
runs the except
code and runserver
runs the try
code.
通过这种方式,除了代码和运行服务器之外,还运行着try代码。
Note the created
boolean, you may use any other way to avoid makemigration
run code that depends on the User.objects....
results
注意创建的布尔值,您可以使用任何其他办法避免makemigration运行代码取决于User.objects ....结果
#2
0
./manage.py migrate
if your Django version is 1.9 or lower, use
如果您的Django版本是1.9或更低,请使用
./manage.py syncdb
then
然后
python manage.py createsuperuser
more details on https://github.com/django/django/blob/master/django/contrib/auth/forms.py
在https://github.com/django/django/blob/master/django/contrib/auth/forms.py上的更多细节
May it help
它可以帮助
#1
1
The problem is this line:
问题是这条线:
File "C:\Python27\lib\site-packages\guardian\management\__init__.py", line 33, in create_anonymous_user User.objects.get(**lookup)
文件“C:\ Python27 \ lib \ \ __init__卫报网站\ \管理。py",第33行,在create_signatous_user .objects.get(**查找)中
guardian\management\__init__.py
is calling User
before it is defined.
卫报\ \ __init__管理。py在定义用户之前调用它。
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)
为什么它在定义之前被调用?…好吧,这是通过mak移民来了解数据库中是否有变化来定义它们(发现的变化)
...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
)
我也有同样的问题,但违规的代码是我自己的代码(不是像guardian这样的库)
My code was like this:
我的代码是这样的:
CHAT_BOT_USER, created = User.objects.get_or_create(username='rosty', \ email=settings.EMAIL_HOST_USER)
CHAT_BOT_USER,= User.objects创建。get_or_create(用户名= ' rosty \电子邮件= settings.EMAIL_HOST_USER)
The offending part is the User
being used before the auth_user
table is created
违规部分是在创建auth_user表之前使用的用户
I solved by only executing the code when the table is present. This happens when there is no OperationError
. And you can know it with a try/except
like this:
我只在表存在时才执行代码。这发生在没有操作错误时。你只要试一试就知道了/除了:
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()
This way makemigrations
runs the except
code and runserver
runs the try
code.
通过这种方式,除了代码和运行服务器之外,还运行着try代码。
Note the created
boolean, you may use any other way to avoid makemigration
run code that depends on the User.objects....
results
注意创建的布尔值,您可以使用任何其他办法避免makemigration运行代码取决于User.objects ....结果
#2
0
./manage.py migrate
if your Django version is 1.9 or lower, use
如果您的Django版本是1.9或更低,请使用
./manage.py syncdb
then
然后
python manage.py createsuperuser
more details on https://github.com/django/django/blob/master/django/contrib/auth/forms.py
在https://github.com/django/django/blob/master/django/contrib/auth/forms.py上的更多细节
May it help
它可以帮助