I am getting the error
"The model backing the 'DataContext' context has changed since the database was created. Consider using Code First Migrations to update the database".
I am using Entity Framework and have changed my model after declaring DataContext
. How can I fix this error?
If you delete the __MigrationHistory
table in SQL Server it should fix it.
If you already deployed your application or you don't want remove data from database you must read about Code First Migrations. Here you have a link: http://msdn.microsoft.com/en-us/library/hh770484(v=vs.103).aspx
If you can delete database just do it. EF will create new database that match your model.
You can also disable creating/updating database structure by invoking the following code:
Database.SetInitializer<MyDbContext>(null);
I used database first to create a project after I had changed my database context and solved my problem:
Database.SetInitializer<Models.YourDbContext>(null);
Don't forget to handle the DbUpdateException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With