0
votes

I am using MVC 5 and EF 6 with Code First. I got this error every time I tried to log in:

The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

This program is ok for 2 years in development until this strange error come this week. Normally after we change the model, we just simply update-database and everything ok. Today we try to do the same and no error returned :

PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No pending explicit migrations.
Applying automatic migration: 202012212240459_AutomaticMigration.
Running Seed method.
PM>

We are using automated migration. But i just try to add migration manually and update-database again successfully but still returning same error.

We tried to remove the database and recreate again using update-database and a new database created, create a dummy account but still returning the same error. Tried following and checking some suggestions in other threads and still not get a good result. Deleting migration history solved the error but when we update-database for future update it will create a duplicate error, so this is not counted as a solution. I don't know what to debug anymore and what to check. Any help is appreciated. Thank you.

1
Have you added a new migration after changing the model and before updating database? - Rob White
@RobWhite Hi, we are using automated migration. But I just tried to add-migration manually and run the update-database succesfully but still returning the error. I will add it in question - Jun Rikson
Have you come across this stackoverflow question? stackoverflow.com/questions/14948205/… I don't know if you've got several projects in your solution using entity framework. Apparently having different versions can cause this issue - Rob White
@RobWhite Yes, we done that every time doing major changes. When I said we tried to remove and recreate the database, I mean doing like in that thread said. - Jun Rikson
I wasn't referring the main answer but one further down the thread (I don't know how to link to specific answers). Do you have multiple projects using entity framwork? - Rob White

1 Answers

0
votes

I think; you change your entity class, 1 - Check your entites 2 - Check your DbSet in Context class 4 Check you entity frame work version 3- remove last migration and re install