Wigtail 1.8.1迁移问题

时间:2017-02-21 11:09:44

标签: django wagtail

尝试将Wagtail从1.7升级到1.8.1但我们在运行迁移时遇到以下错误。我们正在使用Postgres db。

Applying wagtailimages.0016_deprecate_rendition_filter_relation...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, 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 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 345, 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 204, 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 495, 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 117, in _alter_field
    new_db_params, strict,
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 649, in _alter_field
    params,
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 112, in execute
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  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.IntegrityError: could not create unique index "wagtailimages_rendition_image_id_742f4fe4119535f1_uniq"
DETAIL:  Key (image_id, filter_id, focal_point_key)=(507, 4, 2617-1240-3472x35) is duplicated.

这是psql命令的输出

Table "public.wagtailimages_rendition"
     Column      |          Type          |                              Modifiers
-----------------+------------------------+-------------------------- --------------------------------------------
 id              | integer                | not null default   nextval('wagtailimages_rendition_id_seq'::regclass)
 filter_id       | integer                |
 file            | character varying(100) | not null
 width           | integer                | not null
 height          | integer                | not null
 image_id        | integer                | not null
 focal_point_key | character varying(255) | not null
 filter_spec     | character varying(255) | not null
Indexes:
    "wagtailimages_rendition_pkey" PRIMARY KEY, btree (id)
    "wagtailimages_rendition_image_id_323c8fe0_uniq" UNIQUE CONSTRAINT, btree (image_id, filter_spec, focal_point_key)
    "wagtailimages_rendition_58c64917" btree (filter_spec)
    "wagtailimages_rendition_filter_id" btree (filter_id)
    "wagtailimages_rendition_filter_spec_1cba3201_like" btree (filter_spec varchar_pattern_ops)
    "wagtailimages_rendition_image_id" btree (image_id)
Foreign-key constraints:

sql import中的错误是psql:foxtail.sql:68823:

ERROR:  constraint    "wagtailcore__content_type_id_c28424df_fk_django_content_type_id" for  relation "wagtailcore_page" already exists
psql:foxtail.sql:68831: ERROR:  constraint   "wagtailcore_collection_id_5423575a_fk_wagtailcore_collection_id" for   relation "wagtailcore_groupcollectionpermission" already exists
ALTER TABLE
psql:foxtail.sql:68847: ERROR:  constraint   "wagtailcore_groupc_permission_id_1b626275_fk_auth_permission_id" for   relation "wagtailcore_groupcollectionpermission" already exists
psql:foxtail.sql:68855: ERROR:  constraint   "wagtailcore_groupcollectionp_group_id_05d61460_fk_auth_group_id" for   relation "wagtailcore_groupcollectionpermission" already exists
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
psql:foxtail.sql:68903: ERROR:  constraint  "wagtaildocs_collection_id_23881625_fk_wagtailcore_collection_id" for  relation "wagtaildocs_document" already exists
psql:foxtail.sql:68911: ERROR:  constraint  "wagtaildocs_docume_uploaded_by_user_id_17258b41_fk_auth_user_id" for   relation "wagtaildocs_document" already exists
ALTER TABLE
psql:foxtail.sql:68927: ERROR:  constraint   "wagtailimag_collection_id_c2f8af7e_fk_wagtailcore_collection_id" for    relation "wagtailimages_image" already exists

全新导入后但在运行迁移之前输出

Table "public.wagtailimages_rendition"
Column      |          Type          |                                 Modifiers
-----------------+------------------------+--------------------------   --------------------------------------------
id              | integer                | not null default   nextval('wagtailimages_rendition_id_seq'::regclass)
filter_id       | integer                | not null
file            | character varying(100) | not null
width           | integer                | not null
height          | integer                | not null
image_id        | integer                | not null
focal_point_key | character varying(255) | not null
Indexes:
"wagtailimages_rendition_pkey" PRIMARY KEY, btree (id)
"wagtailimages_rendition_image_id_742f4fe4119535f1_uniq" UNIQUE  CONSTRAINT, btree (image_id, filter_id, focal_point_key)
"wagtailimages_rendition_filter_id" btree (filter_id)
"wagtailimages_rendition_image_id" btree (image_id)
Foreign-key constraints:
"filter_id_refs_id_6909da8c" FOREIGN KEY (filter_id) REFERENCES   wagtailimages_filter(id) DEFERRABLE INITIALLY DEFERRED
"image_id_refs_id_e221c01d" FOREIGN KEY (image_id) REFERENCES   wagtailimages_image(id) DEFERRA:

2 个答案:

答案 0 :(得分:1)

由于我无法理解上述情况是如何产生的,我只能建议“核选项”:通过运行

删除wagtailimages_rendition表的内容
DELETE FROM wagtailimages_rendition;
Postgresql命令行上的

。这应该允许剩余的迁移完成而不会出错。这将不会造成持久的数据丢失,因为Wagtail将在需要时重新生成再现 - 尽管页面请求将在一段时间内变慢,因为它必须重新渲染每个图像,其中缺少再现条目。

更新:不是删除所有内容,更保守的方法是查找和删除重复记录:

DELETE FROM wagtailimages_rendition
WHERE image_id || '-' || filter_id || '-' || focal_point_key IN (
    SELECT image_id || '-' || filter_id || '-' || focal_point_key
    FROM (
        SELECT image_id, filter_id, focal_point_key, COUNT(*) AS count
        FROM wagtailimages_rendition GROUP BY image_id, filter_id, focal_point_key
    ) AS renditions
    WHERE count > 1
);

答案 1 :(得分:0)

我可以确认乔斯在这方面看到了什么。

我猜测由于某种原因,我们的focal_point_key值比其他人长,否则每个人在迁移时都会看到这个问题。

这可能是因为您过去为我们做过的一些自定义工作吗?

现在不确定解决方案是什么,任何帮助,非常感谢。