JuanDYB
JuanDYB

Reputation: 744

Entity Framework migration Model First

I have created an EDMX model using the tables of the Database. Now I want to do some changes on my model and them sync those changes to the Database.

I have read that I have to execute enable-migrations command in the nuget console to do this. When I execute the command I get the following error.

Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.

What I want is doing changes during the development to the model and sync it automatically with the database and also execute some SQL Scripts after migration from model to database occurs but I get the error that I have shown you.

Upvotes: 2

Views: 5591

Answers (1)

Steve Greene
Steve Greene

Reputation: 12304

You can't use migrations with model first. There is a schema compare tool in some versions of visual studio you could use to make a script: https://msdn.microsoft.com/en-us/library/hh272690(v=vs.103).aspx

Otherwise you could use Code First to an existing database: http://weblogs.asp.net/scottgu/using-ef-code-first-with-an-existing-database#7579835

Upvotes: 3

Related Questions