在运行从Wagtail 1.7到1.8的迁移时,我收到以下迁移错误:
Applying wagtailimages.0016_deprecate_rendition_filter_relation...Traceback (most recent call last):
File "djangoware/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
fake_initial=fake_initial,
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-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 "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-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 "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 532, in database_forwards
getattr(new_model._meta, self.option_name, set()),
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 329, in alter_unique_together
self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/db/backends/mysql/schema.py", line 83, in _delete_composed_index
return super(DatabaseSchemaEditor, self)._delete_composed_index(model, fields, *args)
File "/Users/nicklo/.virtualenvs/theproject/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 358, in _delete_composed_index
", ".join(columns),
ValueError: Found wrong number (0) of constraints for wagtailimages_rendition(image_id, filter_id, focal_point_key)
这很可能不是一个干净的迁移,因为尝试从1.6.1逐步升级到1.6.3到1.7然后再到1.8第三方应用程序安装尝试跳到1.8所以我有尝试清理迁移并重试。
如果需要,我很乐意尝试通过SQL手动修复此问题。 wagtailimages_rendition表的当前状态是:
CREATE TABLE `wagtailimages_rendition` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`file` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`width` int(11) NOT NULL,
`height` int(11) NOT NULL,
`filter_id` int(11) DEFAULT NULL,
`image_id` int(11) NOT NULL,
`focal_point_key` varchar(17) COLLATE utf8_unicode_ci NOT NULL,
`filter_spec2` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`filter_spec` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `wagtailimages_rendition_f33175e6` (`image_id`),
KEY `wagtailimages_rendition_0a317463` (`filter_id`),
KEY `wagtailimages_rendition_58c64917` (`filter_spec`)
) ENGINE=InnoDB AUTO_INCREMENT=352 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
我注意到我在Wagtail 1.8上运行的另一个项目有以下内容:
CREATE TABLE `wagtailimages_rendition` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`file` varchar(100) NOT NULL,
`width` int(11) NOT NULL,
`height` int(11) NOT NULL,
`focal_point_key` varchar(255) NOT NULL,
`filter_id` int(11) DEFAULT NULL,
`image_id` int(11) NOT NULL,
`filter_spec` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `wagtailimages_rendition_image_id_323c8fe0_uniq` (`image_id`,`filter_spec`,`focal_point_key`),
KEY `wagtailimages_rend_filter_id_7fc52567_fk_wagtailimages_filter_id` (`filter_id`),
KEY `wagtailimages_rendition_58c64917` (`filter_spec`),
KEY `wagtailimages_rendition_f33175e6` (`image_id`),
CONSTRAINT `wagtailimages_rend_filter_id_7fc52567_fk_wagtailimages_filter_id` FOREIGN KEY (`filter_id`) REFERENCES `wagtailimages_filter` (`id`),
CONSTRAINT `wagtailimages_rendit_image_id_3e1fd774_fk_wagtailimages_image_id` FOREIGN KEY (`image_id`) REFERENCES `wagtailimages_image` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=272 DEFAULT CHARSET=utf8;
帮助表明我需要通过SQL做的约束更改可能足以解决问题,但任何建议都表示赞赏。
答案 0 :(得分:1)
我最好的猜测是你受到了Wagtail 1.8中的这个错误的影响:https://github.com/wagtail/wagtail/issues/3256
这会导致迁移0016在操作过程中失败:
migrations.AlterUniqueTogether(
name='rendition',
unique_together=set([('image', 'filter_spec', 'focal_point_key')]),
),
涉及在(image_id,filter_id,focal_point_key)上删除唯一约束并在(image_id,filter_spec,focal_point_key)上创建新约束。后者失败是因为它超出了MySQL在某些配置上的长度限制。
要解决此问题,请确保安装了Wagtail 1.8.1(看起来你已经有了,因为它成功地将focal_point_key
的长度缩短为17个字符)。然后,要在迁移0016之前将数据库状态恢复到正确状态,请运行:
ALTER TABLE wagtailimages_rendition ADD UNIQUE KEY wagtailimages_rendition_image_id_uniq (image_id, filter_id, focal_point_key);
现在manage.py migrate
应该有希望完成剩余的迁移。