EF (Entity Framework) 4.3 Migration tool does not work on EF 4.1 DB

无人久伴 提交于 2019-11-27 16:45:34

问题


I want to modify one DB which was developed with EF 4.1 (Code First). I upgraded the project into EF 4.3 and follow this steps: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx

Everything is going well, but when I want to test on current DB (EF 4.1 Code First), Update-Database raise this error:

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).

I was wondering how I can migrate an EF 4.1 (Code First) DB? Moreover that DB is live and has data and I cannot drop tables.


回答1:


You need to create an empty migration and execute it prior to doing changes to your model. It will create the migration history table for you. After that you can use migrations for new changes. I wrote walkthrough article about this topic.




回答2:


Run "Add-Migration InitialMigration -IgnoreChanges" before doing any changes to the model.. Make the required changes, then run "update-database"



来源:https://stackoverflow.com/questions/9523133/ef-entity-framework-4-3-migration-tool-does-not-work-on-ef-4-1-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!