對不起,發佈這樣一個普遍的問題,但這可能有多種情況下的多個答案(我可能必須重新創建分貝,才能得到答案),所以在這裏去:EF6代碼遷移 - 數據庫是不同的,但仍然相同
我們有一個使用EF6的C#項目,它已經成功地利用EF遷移數月。今天早上,當我嘗試運行我的項目,我得到這個這一切太熟悉的錯誤:
System.Data.Entity.Migrations.Infrastructure.AutomaticMigrationsDisabledException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
除了我找不到任何東西的證據已經改變。
- 數據庫的__MigrationHistory表與項目中的遷移相匹配。
- 如果我做了一個「添加遷移」,它會出現空的Up DownDown方法。
- 我們從幾個晚前(當我們知道它工作的時候)恢復了一個數據庫到一個臨時數據庫並進行了比較,並且沒有發現結構變化。
- 我甚至試圖運行「更新數據庫」的空遷移,這工作,但錯誤仍然發生。
有關如何發生這種情況的任何想法?
您是否運行了命令'Enable-Migrations'?然後運行'update-database'。或者使用update-database -force。如果不檢查AutomaticMigrationsEnabled並將其設置爲AutomaticMigrationsEnabled = true – DSR 2014-09-24 14:05:30
「enable-migrations」說「遷移已啓用」。 「update-database -force」說「沒有掛起明確的遷移」。之後,如果我運行該項目,我仍然會收到錯誤消息。 – 2014-09-24 14:21:29
使用-ConnectionProviderName和-ConnectionString與您的添加遷移和更新數據庫以確保遷移使用正確的數據庫,我在我的項目中有這樣的問題。 – Masoud 2014-09-24 16:43:27