我有一个django项目正在开发中,但尚未经过测试。最近,我一直在运行测试命令python manage.py test,但是出现以下错误。
psycopg2.ProgrammingError: relation "auth_group" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/commands/test.py", line 56, in handle
failures = test_runner.run_tests(test_labels)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/test/runner.py", line 604, in run_tests
old_config = self.setup_databases()
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/test/runner.py", line 551, in setup_databases
self.parallel, **kwargs
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/test/utils.py", line 174, in setup_databases
serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 68, in create_test_db
run_syncdb=True,
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 148, in call_command
return command.execute(*args, **defaults)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 172, in handle
self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 310, in sync_apps
self.stdout.write(" Running deferred SQL...\n")
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 106, in __exit__
self.execute(sql)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 133, in execute
cursor.execute(sql, params)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/raven/contrib/django/client.py", line 127, in execute
return real_execute(self, sql, params)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/teddy/Desktop/Mookh_Works/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "auth_group" does not exist
以下是我的设置文件:
LOCAL_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sites',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
]
INSTALLED_APPS = [
# 'cachalot',
'celery',
'corsheaders',
'django_countries',
'django_filters',
'generic_relations',
'django_celery_beat',
'haystack',
'silk',
'raven.contrib.django.raven_compat',
'rest_framework_filters',
'rest_framework',
'rest_framework_jwt',
'rest_framework_cache',
'rolepermissions',
'storages',
]
我一直猜测它与django.contrib.auth有关,但是我无法找到错误的原因,甚至无法在测试开始前在哪里创建表。 可能是什么原因?