Entity Framework migration Model First

c# entity-framework entity-framework-6 sql-server

Question

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.

1
2
2/26/2015 5:44:20 PM

Popular Answer

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

2
2/26/2015 9:17:37 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow