Django 升级:关系"django_content type"不存在



我将 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

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

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

相关内容

  • 没有找到相关文章

最新更新