Django 1.8 test issue: ProgrammingError: relation "auth_user" does not exist
Django 1.8 test issue: ProgrammingError: relation "auth_user" does not exist
我最近将 Django 升级到 1.8 并设置了一个新的开发数据库以重新开始。迁移和依赖关系进行得很顺利,避免了你遇到的常见错误,你最终解决了。该应用程序现在在本地运行正常。
但是,我在尝试 运行 测试时遇到错误:
python manage.py test
这是我收到的错误:
django.db.utils.ProgrammingError: relation "auth_user" does not exist
不用说了,Django的auth模块确实是在app里面安装和迁移的,所以我也不知道是怎么回事。
这是完整的堆栈跟踪,以防您需要查看它,但它并没有说明任何对我找出此错误原因的远程帮助:
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
我可以在 this answer 之后想出一个解决方法,它可以防止测试任务从 运行 宁 migrate
,根据我一直在阅读的内容,这应该是错误的地方发生。够奇怪的,因为当我 运行 migrate
一切都很好。
但是,我宁愿不诉诸厚颜无耻的解决方法,而是坚持按设计做事。此外,此错误可能暗示其他问题实际上是错误的并且应该被修复。
一些解决方案建议 运行ning:
python manage.py migrate auth
python manage.py migrate
但这没有任何作用,因为我的项目中没有待处理的迁移。
我该如何解决这个神秘的问题?
如果您有任何具有指向 auth.User
的外键的应用程序,请确保这些应用程序的初始迁移在授权应用程序上具有 dependency:
class Migration(migrations.Migration):
dependencies = [('auth', '__first__')]
我遇到了同样的问题,当我迁移了项目中包含的应用程序之一但迁移不会自动执行时,问题终于解决了。
所以只需检查您的应用程序,然后手动执行 ./manage.py makemigrations YOUR_APP_NAME
和 ./manage.py migrate
。
我最近将 Django 升级到 1.8 并设置了一个新的开发数据库以重新开始。迁移和依赖关系进行得很顺利,避免了你遇到的常见错误,你最终解决了。该应用程序现在在本地运行正常。
但是,我在尝试 运行 测试时遇到错误:
python manage.py test
这是我收到的错误:
django.db.utils.ProgrammingError: relation "auth_user" does not exist
不用说了,Django的auth模块确实是在app里面安装和迁移的,所以我也不知道是怎么回事。
这是完整的堆栈跟踪,以防您需要查看它,但它并没有说明任何对我找出此错误原因的远程帮助:
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
我可以在 this answer 之后想出一个解决方法,它可以防止测试任务从 运行 宁 migrate
,根据我一直在阅读的内容,这应该是错误的地方发生。够奇怪的,因为当我 运行 migrate
一切都很好。
但是,我宁愿不诉诸厚颜无耻的解决方法,而是坚持按设计做事。此外,此错误可能暗示其他问题实际上是错误的并且应该被修复。
一些解决方案建议 运行ning:
python manage.py migrate auth
python manage.py migrate
但这没有任何作用,因为我的项目中没有待处理的迁移。
我该如何解决这个神秘的问题?
如果您有任何具有指向 auth.User
的外键的应用程序,请确保这些应用程序的初始迁移在授权应用程序上具有 dependency:
class Migration(migrations.Migration):
dependencies = [('auth', '__first__')]
我遇到了同样的问题,当我迁移了项目中包含的应用程序之一但迁移不会自动执行时,问题终于解决了。
所以只需检查您的应用程序,然后手动执行 ./manage.py makemigrations YOUR_APP_NAME
和 ./manage.py migrate
。