Django 1.8测试问题:ProgrammingError:关系"auth_user"不存在 [英] Django 1.8 test issue: ProgrammingError: relation "auth_user" does not exist
问题描述
我最近将Django升级到1.8,并建立了新的开发数据库以重新开始.迁移和依存关系进行得很好,可以避免遇到的常见错误,并最终解决.该应用现在可以在本地运行.
I recently upgraded Django to 1.8 and set up a new development database for a fresh start. Migrations and dependencies went well, safe the usual errors you get and you end up solving. The app is working locally now just fine.
但是,尝试运行测试时出现错误:
However, I am getting an error when trying to run tests:
python manage.py test
这是我得到的错误:
django.db.utils.ProgrammingError: relation "auth_user" does not exist
不用说,Django的auth模块确实已安装并已在应用程序中迁移,因此我不确定发生了什么.
Needless to say, Django's auth module is indeed installed and migrated in the app, so I am not sure what is going on.
这里是完整的堆栈跟踪信息,以备您窥视,但它对我来说甚至没有任何帮助,找出导致此错误的原因:
Here is the full stacktrace in case you need to peek at it, but it does't say anything even remotely helpful to me to figure out the cause of this error:
Traceback (most recent call last):
File "C:/Users/dabadaba/PycharmProjects/dogpatchsports_com/mysite/manage_sched_dev.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
utility.execute()
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 445, in execute
output = self.handle(*args, **options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 166, in setup_databases
**kwargs
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\base\creation.py", line 368, in create_test_db
test_flush=not keepdb,
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 445, in execute
output = self.handle(*args, **options)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\migrate.py", line 318, in sync_apps
cursor.execute(statement)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\utils.py", line 98, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
我可以在此答案之后找出解决方法,该方法可防止测试任务运行migrate
,根据我一直在阅读的内容应该是发生错误的地方.奇怪的是,因为当我运行migrate
时,一切都很好.
I can figure out a workaround following this answer which prevents the test task from running migrate
, which according to what I have been reading should be the point where the error happens. Odd enough, since when I run migrate
everything is fine.
但是,我宁愿不要诉诸于厚颜无耻的变通办法,而要按照设计来做事.此外,此错误可能暗示着其他问题实际上是错误的,应予以修复.
However, I would prefer not to resort to a cheeky workaround and stick to doing things as they are designed. Additionally, this error might be a hint that something else is actually wrong and ought to be fixed.
一些解决方案建议运行:
Some solutions suggest running:
python manage.py migrate auth
python manage.py migrate
但这无济于事,因为我的项目中没有待处理的迁移.
But that does nothing since there are no pending migrations in my project.
我该如何解决这个神秘的问题?
How can I solve this mysterious issue?
推荐答案
如果您有任何具有auth.User
外键的应用程序,请确保这些应用程序的初始迁移具有
If you have any apps which have foreign keys to auth.User
, then make sure that the initial migrations for those apps have a dependency on the auth app:
class Migration(migrations.Migration):
dependencies = [('auth', '__first__')]
这篇关于Django 1.8测试问题:ProgrammingError:关系"auth_user"不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!