环境:Ubuntu / Apache
运行迁移时出现以下错误。错误下方是迁移文件。迁移在dev计算机上运行正常,但在尝试部署时出错。这个错误出现在Django代码中,所以我没有太多的事情可以解决这个问题。迁移摘要是,它正在从三个null=True
字段中删除ManyToManyField
,并且正在更改显示的其余字段的upload_to
值。 Django(1.11.9)和psycopg2(2.7.3.2)版本在两台机器上都匹配。是否可以从此错误消息中判断哪个字段(如果特定字段是问题)导致错误?
Running migrations:
Applying manager.0035_auto_20180119_1138...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/fields.py", line 221, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 500, in alter_field
return self._alter_many_to_many(model, old_field, new_field, strict)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 845, in _alter_many_to_many
new_field.remote_field.through._meta.get_field(new_field.m2m_reverse_field_name()),
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 515, in alter_field
old_db_params, new_db_params, strict)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql/schema.py", line 112, in _alter_field
new_db_params, strict,
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 524, in _alter_field
fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 995, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql/introspection.py", line 233, in get_constraints
""", [table_name])
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "ORDER"
LINE 3: indexname, array_agg(attname ORDER BY rnum),...
以下是失败的迁移文件:
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2018-01-19 12:10
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('manager', '0034_auto_20170126_1808'),
]
operations = [
migrations.AlterField(
model_name='book',
name='topics',
field=models.ManyToManyField(blank=True, to='manager.Topic'),
),
migrations.AlterField(
model_name='catalog',
name='books',
field=models.ManyToManyField(blank=True, to='manager.Book'),
),
migrations.AlterField(
model_name='catalog',
name='thumb',
field=models.ImageField(blank=True, null=True, upload_to=b'images/catalogs/'),
),
migrations.AlterField(
model_name='customer',
name='email_lists',
field=models.ManyToManyField(blank=True, to='manager.EmailList'),
),
migrations.AlterField(
model_name='graphic',
name='image',
field=models.ImageField(blank=True, null=True, upload_to=b'images'),
),
migrations.AlterField(
model_name='graphic',
name='thumb',
field=models.ImageField(blank=True, null=True, upload_to=b'images/thumb/'),
),
migrations.AlterField(
model_name='navigationitem',
name='image',
field=models.ImageField(blank=True, null=True, upload_to=b'images/nav/'),
),
migrations.AlterField(
model_name='navigationitem',
name='rollover',
field=models.ImageField(blank=True, null=True, upload_to=b'images/nav/'),
),
migrations.AlterField(
model_name='photo',
name='image',
field=models.ImageField(blank=True, null=True, upload_to=b'images'),
),
migrations.AlterField(
model_name='photo',
name='thumb',
field=models.ImageField(blank=True, null=True, upload_to=b'images/thumb/'),
),
migrations.AlterField(
model_name='template',
name='html',
field=models.FileField(blank=True, null=True, upload_to=b'page_templates/'),
),
]
答案 0 :(得分:1)
您的错误类似于ticket 28736中的错误,因此看起来您正在运行PostgreSQL 8.X.
Django 1.11 requires at least PostgreSQL 9.3。