0

我将 django 版本从 1.7.5 升级到 1.9.2。所有迁移都运行了,但是当我运行测试时,我得到了以下错误。

django.db.utils.ProgrammingError: relation "django_content_type" does not exist

我检查了数据库并且存在 django_content_type 模型。我正在使用 PostgreSQL。

我只在 PostgreSQL 上而不是在 Sqlite3 上收到此错误。

追溯

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 129, in 
    utility.execute()
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 104, in execute
    PycharmTestCommand().run_from_argv(self.argv)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_manage.py", line 91, in handle
    failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive, failfast=failfast, keepdb='--keepdb' in sys.argv)
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 256, in run_tests
    extra_tests=extra_tests, **options)
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/django_test_runner.py", line 156, in run_tests
    return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/test/runner.py", line 532, in run_tests
    old_config = self.setup_databases()
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/test/runner.py", line 482, in setup_databases
    self.parallel, **kwargs
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/test/runner.py", line 726, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
    run_syncdb=True,
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/__init__.py", line 119, in call_command
    return command.execute(*args, **defaults)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 172, in handle
    self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 293, in sync_apps
    cursor.execute(statement)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/Mac/my_env_test/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
4

1 回答 1

1

我在旧 Django 版本中使用了 uuid 字段和 JSON 字段,但在新版本中,这些字段是 django 模型默认提供的。所以我用 django 默认字段替换了这些字段并再次创建了迁移....

现在它的工作没有任何问题..

于 2016-02-17T06:06:35.900 回答