Django 3无法迁移位于或接近“WITH ORDINALITY”的DB语法错误

2024-04-23 12:23:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近将服务器从Python2.7升级到Python3.7,并将Django从1.11升级到3.0.6。大多数情况都很好,但我无法迁移数据库。以下链接:Errors when I try to migrate in Django2我删除了所有迁移,运行了一个新的makemigrations,做了一个新的迁移——假迁移,一切都正常

然后我更新了models.py文件,它给了我同样的错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 233, in handle
    fake_initial=fake_initial,
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 565, in alter_field
    old_db_params, new_db_params, strict)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/postgresql/schema.py", line 154, in _alter_field
    new_db_params, strict,
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 573, in _alter_field
    fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 1148, in _constraint_names
    constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/postgresql/introspection.py", line 166, in get_constraints
    """, [table_name])
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/webapps/jboycecom/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "WITH ORDINALITY"
LINE 6:                     FROM unnest(c.conkey) WITH ORDINALITY co...

我觉得我可能在更新Django时把数据库搞砸了,因为它抱怨我不再使用一个不工作的oauth2导入,但由于我无法迁移数据库,我只是删除了有问题的模型,其他所有的都编译好了,工作正常

我不知道还能尝试什么。前面链接的一部分说“截断_django_migrations_uu表”,但我不知道怎么做。谷歌没有给我任何帮助。也许这会有帮助


Tags: djangoinpyselfexecutedblibpackages
1条回答
网友
1楼 · 发布于 2024-04-23 12:23:02

嗯,我想不出来,所以我只是删除了整个数据库,并将通过预先导出的电子表格重新填充


事实上,这并没有解决问题。如果我尝试迁移数据库,尝试将更改迁移到Django中的ForeignKey或ManyToManyFields会出现错误。我创建了一个新的CharField,它迁移得很好

我正在运行PSQL9.5.21和Psycopg2.8.5,所以这些都不是问题所在

相关问题 更多 >