EF6 Code first "model backing DataContext has changed" error (.mdf Db)

ef-code-first entity-framework-6 wpf

Question

The code first methodology is new to me.

This error is occurring for me:

"Since the database's creation, the model that supports the "DataContext" context has changed. Consider updating the database using Code First Migrations ".

I'm running a WPF application utilizing EF6 and MVVM against a local database (.mdf life).

I introduced a new DbSet collection called langauges to my datacontext after creating a new model called langauges.

I receive the aforementioned issue when the code tries to instantiate a datacontext object.

What am I overlooking? For all of my other new tables and models, I simply had to write the code to create them, use a test method to add a record to the new table or model, and then run EF code first to have it create the new table and add the record without any issues. Why is it failing right now?

1
1
2/28/2014 1:33:31 PM

Accepted Answer

EF6 code initially does not by default recreate your database. That is what the exemption states. It also includes the answer to your dilemma. Use Code First Migrations, please.

Type the following into the PackageManager Console after opening it.

  1. Enable-Migrations
  2. Add-Migration Name (will produce a class with the modifications To make it simple to return to the original state, I always use the term "Init" for the first.
  3. Update-Database (this will update your database)

More details are available at MSDN.

3
2/28/2014 4:38:15 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