0
運行在服務器上,而不是混帳回購協議

我升級狂歡商務部從3.0版本到3.1版本,但忘記從我的本地開發環境上的Git遷移文件檢查定影軌道遷移使用Capistrano的

我,而不是生成的遷移文件而不是在服務器上;我最終將從開發環境遷移到git,但現在我在部署時遇到了各種各樣的問題,因爲它試圖在表存在時運行遷移。

我想我並不需要遷移,因爲它在服務器上運行?

運行在服務器上顯示rake db:migrate:status

up  20151015124064 Add meta title to page.spree static content 
    up  20151015124065 Add render as partial for layout for spree pages.spree static content 
    up  20151015124066 Add pages stores.spree static content 
    down 20160707102753 Create spree store credits.spree 
    down 20160707102754 Create spree store credit categories.spree 
    down 20160707102755 Create spree store credit events.spree 
    down 20160707102756 Create spree store credit types.spree 
    down 20160707102757 Add missing indexes.spree 
    down 20160707102758 Remove duplicated indexes from multi columns.spree 
    down 20160707102759 Remove user index from spree state changes.spree 
    down 20160707102760 Add position to spree payment methods.spree 
    down 20160707102761 Add taxable adjustment total to line item.spree 
    down 20160707102762 Migrate payment methods display.spree 
    down 20160707102763 Spree payment method store credits.spree 
    down 20160707102764 Rename has and belongs to associations to model names.spree 
    down 20160707102765 Spree store credit types.spree 
    down 20160707102766 Add discontinued to products and variants.spree 
    down 20160707102767 Remove shipping method id from spree orders.spree 
    down 20160707102768 Add id column to earlier habtm tables.spree 
    down 20160707102769 Add indexes.spree 
    down 20160707102770 Add missing indices on user.spree auth 
    down 20160707102771 Remove show in footer from spree pages.spree static content 

在我的位置的機器它表明:

up  20151015124064 Add meta title to page.spree static content 
    up  20151015124065 Add render as partial for layout for spree pages.spree static content 
    up  20151015124066 Add pages stores.spree static content 
    up  20160707102753 Create spree store credits.spree 
    up  20160707102754 Create spree store credit categories.spree 
    up  20160707102755 Create spree store credit events.spree 
    up  20160707102756 Create spree store credit types.spree 
    up  20160707102757 Add missing indexes.spree 
    up  20160707102758 Remove duplicated indexes from multi columns.spree 
    up  20160707102759 Remove user index from spree state changes.spree 
    up  20160707102760 Add position to spree payment methods.spree 
    up  20160707102761 Add taxable adjustment total to line item.spree 
    up  20160707102762 Migrate payment methods display.spree 
    up  20160707102763 Spree payment method store credits.spree 
    up  20160707102764 Rename has and belongs to associations to model names.spree 
    up  20160707102765 Spree store credit types.spree 
    up  20160707102766 Add discontinued to products and variants.spree 
    up  20160707102767 Remove shipping method id from spree orders.spree 
    up  20160707102768 Add id column to earlier habtm tables.spree 
    up  20160707102769 Add indexes.spree 
    up  20160707102770 Add missing indices on user.spree auth 
    up  20160707102771 Remove show in footer from spree pages.spree static content 

我相信在服務器上遷移狀態應該是updown

是否有任何提示我應該如何處理?

回答

0

如果你沒有任何數據丟失,你可以從你的SQL控制檯,然後重新運行Capistrano的部署或丟棄這些表,你可以手動up從服務器通過

rake db:migrate:up VERSION=20151015124064 

遷移文件其中version是rake db:migrate:status

注意結果的第二列:記得你不得不放棄對兩種情況下這些表

+0

感謝Vishal,我確實有數據,不幸的是,我嘗試遷移:因爲表已經存在,所以失敗了。丟棄表格很好,但有不可逆轉的遷移。 –

+0

不可逆遷移是spree表或其他表的一部分,如果可能的話,您可以列出不可逆遷移文件。 –

+0

並且由於遷移不成功,您可以添加2個方法** def up **和** def down **而不是** def change **在所有不可逆轉的遷移中,因此您可以編寫用於遷移和回滾的不同邏輯。我們可以通過轉儲SQL來保留數據。 –

0

如果您不想丟失數據並重新執行,則可以嘗試另一種方法。

遷移被標記爲updown,具體取決於遷移版本是否作爲schema_migrations表內的記錄存在。 所以,你可以解決您的問題的一種方法是添加包含以下內容的文件app/models/schema_migration.rb

class SchemaMigration < ActiveRecord::Base 
    self.primary_key = :version 
    attr_accessible :version 

    # you can call the method below via console or even call 
    # or execute the commands directly from the rails console 
    def self.fix_migrations 
    # basically a list of all migrations that you run on server but are not marked as up 
    down_migrations = %w(20160707102753 20160707102754 ... 20160707102771) 
    down_migrations.each do |m| 
     # this will add an entry in the schema_migrations datatable 
     # on server so rake db:migrate won't try to run these again 
     SchemaMigration.create(version: m) 
    end   
    end 

end 

,然後通過軌道控制檯,您執行:SchemaMigration.fix_migrations

如果您需要再次運行特定遷移,或者意外添加了以前從未執行的遷移版本,則可以始終使用SchemaMigration.find_by_version('xxxx').delete從schema_migrations刪除條目。這將允許rake db:migrate嘗試再次運行該遷移。