Error modifying Entity Framework model

I get an error

“The model supporting the DataContext has changed since the database was created. Consider using First First Migrations to update the database.”

I am using Entity Framework and have changed my model after declaring a DataContext . How can I fix this error?

+8
entity-framework-5 asp.net-mvc-4 datacontext
source share
4 answers
  • If you have already deployed your application or do not want to delete data from the database, you should read about the First Migration Codes. Here you have a link: http://msdn.microsoft.com/en-us/library/hh770484(v=vs.103).aspx

  • If you can delete the database, just do it. EF will create a new database that matches your model.

  • You can also disable creating / updating the database structure by calling the following code:

     Database.SetInitializer<MyDbContext>(null); 
+7
source share

If you delete the __MigrationHistory table in SQL Server, it should fix it.

+9
source share

I used the database first to create the project after I changed my database context and solved my problem:

 Database.SetInitializer<Models.YourDbContext>(null); 

Remember to handle a DbUpdateException

+1
source share

Delete the __MigrationHistory table in SQL Server or just or all rows of this table, it should fix it

0
source share

All Articles