6

我想修改一個使用EF 4.1(代碼優先)開發的DB。我升級項目到EF 4.3,並按照此步驟: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspxEF(Entity Framework)4.3遷移工具不適用於EF 4.1 DB

一切都很順利,但是當我想測試當前的DB(EF 4.1代碼第一次),更新數據庫內提出這個錯誤:

Cannot scaffold the next migration because the target database was created with a version of Code First earlier than EF 4.3 and does not contain the migrations history table. To start using migrations against this database, ensure the current model is compatible with the target database and execute the migrations Update process. (In Visual Studio you can use the Update-Database command from Package Manager Console to execute the migrations Update process).

我想知道如何遷移EF 4.1(Code First)數據庫?此外,數據庫是活的,有數據,我不能丟表。

+1

讀取錯誤消息。按照指示。 – jrummell 2012-03-01 20:36:59

+0

但這是一個遞歸錯誤消息。 – 2012-03-05 00:50:25

回答

8

您需要創建空遷移並在對模型進行更改之前執行它。它將爲您創建遷移歷史記錄表。之後,您可以使用遷移進行新的更改。我寫了關於這個話題的walkthrough article

+0

Hi Ladislav,我按照你的指示,但是當我想在軟件包管理器控制檯(PM> Add-Migration InitialMigration -IgnoreChanges)中添加初始遷移時,它又提出了這個錯誤:「不能支持下一次遷移,因爲目標數據庫是用Code First早於EF 4.3的版本,並且不包含遷移歷史記錄表......「 – Pouyan 2012-03-02 17:16:36

+0

它的工作原理是,你應該在做任何修改之前完成」Add-Migration InitialMigration -IgnoreChanges「 – Pouyan 2012-03-02 18:22:48

+0

這是上次提到的文章的段落。 – 2012-03-02 20:41:08

0

運行做對模型進行任何更改之前「添加遷移InitialMigration -IgnoreChanges」 ..進行必要的更改,然後運行「更新數據庫」