試圖將Wagtail從1.7升級到1.8.1,但運行遷移時出現以下錯誤。我們正在使用Postgres數據庫。W 1.8 1.8.1遷移問題
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導入的錯誤是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:
我對這個錯誤有些困惑,因爲有問題的遷移應該是刪除有問題的唯一索引,而不是創建它......請你可以在Postgresql命令行上運行'\ d wagtailimages_rendition'並粘貼在這裏輸出,所以我可以看到數據庫表當前處於什麼狀態? – gasman
我們在本地開發中使用docker,當我在刪除容器後再次嘗試時,遷移運行正常。當我試圖導入某些sql以用一些數據填充數據庫時,出現錯誤,我在管理員中擁有的所有內容都默認爲歡迎使用您的w site站點頁面。雖然它已經導入了用戶等。似乎如果有數據已經存在,遷移失敗。 – joss
看起來您的SQL導入文件包含一些模式更改/創建命令,這些命令在遷移時肯定不會很好,因爲它依賴於從一個特定的初始數據庫狀態開始。我猜想它的目的是從一個空的數據庫開始運行 - 完成沒有錯誤嗎?如果是這樣,那麼如果在此之後運行Wagtail 1.8.1遷移,會發生什麼? – gasman