2016-08-14 128 views
0

我有以下scenario-合併多個遷移實體框架代碼優先

我在我加入了3個新的遷移分支機構的工作 - 爲約定我將它們命名爲

Migration A 
Migration B 
Migration C 

當試圖合併master原來有4個新的遷移,不按時間順序排列(從另一個分支合併)。我的意思是下面

new Migration from master 1 
existing Migration in both branches 
existing Migration in both branches 
new Migration from master 2 
new Migration from master 3 
new Migration from master 4 
existing Migration in both branches 
existing Migration in both branches 

當合並出現以下情形現在

new Migration from master 1 
existing Migration in both branches 
existing Migration in both branches 
new Migration from master 2 
new Migration from master 3 
new Migration from master 4 
existing Migration in both branches 
existing Migration in both branches 
Migration A 
Migration B 
Migration C 

顯然實體框架不會放過,因爲它認爲該模式是錯誤的我更新數據庫 - 添加時新的遷移將生成從master提到的4個新遷移中的更改。

真正的問題是,我不能恢復到現有的遷移,然後重新支架來更新元數據,因爲它們不是按時間順序排列 (如在另一個question每接受answer建議)。

我試圖update-database -target回遷移之前new Migration from master 1,然後Add-Migration <timestamp> new Migration from master 1重新腳手架,但我得到了Unable to generate an explicit migration because the following explicit migrations are pending....例外。

我真的不想增加空白遷移來解決這個問題,而是找到一個乾淨和良好的解決方案。

回答

0

經過一些研究後,解決方案是將數據庫更新到最後一個遷移前的數據庫,然後重新構建上一次遷移。

update-database -target Migration B 
add-migration <timestamp>_Migration C 
相關問題