Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 386
Pouyan Avatar asked Mar 01 '12 20:03

Pouyan


People also ask

How do I enable EF migration?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).

How does EF migrations work?

The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.


1 Answers

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.

like image 131
Ladislav Mrnka Avatar answered Oct 19 '22 00:10

Ladislav Mrnka