Ethan Pelton
Ethan Pelton

Reputation: 1796

The model backing the 'DMSContext' context has changed

I'm receiving the following error when running my mvc 4 app.

The model backing the 'DMSContext' context has changed since the database was created. Consider using Code First Migrations to update the database

I am running my app against an existing database and do no want to recreate the db each time the model changes.

I've found plenty of answers on google, but none have worked.

Specifically, I've tried adding the following to my global.asax:

Database.SetInitializer<DMSContext>(null);

and

Database.SetInitializer<DMSContext<Contact>>(null);

in the above, DMSContext is the DbContext. Contact is the Model where the change causing the error originates.

I've also tried adding the following to my context class:

public DMSContext() : base()
          {
             Configuration.AutoDetectChangesEnabled = false;
          }

Most of the direction I've followed is from this page, but no luck.

The model backing the <Database> context has changed since the database was created

Upvotes: 1

Views: 3853

Answers (3)

prime_z
prime_z

Reputation: 544

Check the name of the class, which inherits the DbContext. It's name have to be the same as the name of the connectionString in Web.config

<connectionStrings>
    <add name="TheSameNameAsYourDbContextClass" providerName="" connectionString="" />
  </connectionStrings>

Upvotes: 2

Komengem
Komengem

Reputation: 3774

If you are working with Entity Framework Code First, its recommended that you enable migrations in your application. To do so, see this link.

Now every time you change something in your code (Mostly Entities), just build and then run Update-Database -Force in your Package Manager Console.

Let me know if you have any more questions.

Upvotes: 2

Carlos Corral Carvajal
Carlos Corral Carvajal

Reputation: 526

Although you don't use migrations try to create one, do not run it, but you'll be able to see the differences with the database.

Upvotes: 2

Related Questions