2017-02-21 120 views
1

試圖將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: 
+0

我對這個錯誤有些困惑,因爲有問題的遷移應該是刪除有問題的唯一索引,而不是創建它......請你可以在Postgresql命令行上運行'\ d wagtailimages_rendition'並粘貼在這裏輸出,所以我可以看到數據庫表當前處於什麼狀態? – gasman

+0

我們在本地開發中使用docker,當我在刪除容器後再次嘗試時,遷移運行正常。當我試圖導入某些sql以用一些數據填充數據庫時,出現錯誤,我在管理員中擁有的所有內容都默認爲歡迎使用您的w site站點頁面。雖然它已經導入了用戶等。似乎如果有數據已經​​存在,遷移失敗。 – joss

+0

看起來您的SQL導入文件包含一些模式更改/創建命令,這些命令在遷移時肯定不會很好,因爲它依賴於從一個特定的初始數據庫狀態開始。我猜想它的目的是從一個空的數據庫開始運行 - 完成沒有錯誤嗎?如果是這樣,那麼如果在此之後運行Wagtail 1.8.1遷移,會發生什麼? – gasman

回答

1

既然不能讓情況怎麼上面出現的感覺,我只能建議「核選項」:由PostgreSQL的命令行運行

DELETE FROM wagtailimages_rendition; 

刪除wagtailimages_rendition表的內容。這應該允許剩餘的遷移完成而沒有錯誤。這將不會導致持續的數據丟失,因爲W will將在需要它們時重新生成翻譯 - 儘管頁面請求一段時間會更慢,因爲它必須重新呈現每個映像丟失了翻譯條目的地方。

UPDATE:而不是刪除一切,更保守的方法是找到並刪除重複記錄:

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 
); 
+0

謝謝,這工作。 – joss

+0

在製作過程中,我們不確定是否需要添加我們的再現表,不僅僅是因爲性能,而是因爲外部系統調用w to以生成在django模板之外使用的設置大小的圖像,所以它們將永遠不會以同樣的方式再次調用在頁面上使用的圖像將是。 (如果這是有道理的?)我發現了這個問題,Karl在這個問題中發佈了這一點,https://github.com/wagtail/wagtail/issues/685刪除了重複的表示。我在本地嘗試過,它允許遷移繼續。你認爲這會是一個選擇嗎?謝謝Joss – joss

+0

@joss是的,這應該工作。我認爲你可能需要修改Karl的SQL以在唯一性標準中包含'focal_point_key',以使其與當前模式保持同步 - 我已經更新了我的答案以包含(未經測試的)固定SQL。 – gasman

0

我可以證實什麼喬斯是看到在這一側。

我猜測出於某種原因,我們比其他人擁有更長的focal_point_key值,否則每個人在遷移時都會看到這個問題。

難道這是因爲你過去爲我們做過的一些習慣性工作嗎?

不知道現在解決方案在這裏,任何幫助,非常感謝。