What causes The model backing the 'ApplicationDbContext' context has changed since the database was created

c# entity-framework entity-framework-6

Question

I've got an Entity Framework 6 application. I've ported the database from SQL Server to PostgreSQL. Now when I run the application I'm getting this error:

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).

The only thing is that the database schema shouldn't have changed. If it has, there is something wrong with my port which needs fixing. I do not want to run a migration to bring the database up to the new version. I want to find out what the change was that has caused this so that I can correct it.

Does anyone know how Entity Framework decides whether the database is out of date and what causes it to raise this error?

1
1
8/17/2018 10:33:37 AM

Accepted Answer

Entity Framework stores migration history and the state of your database model in a table called MigrationHistory.

This document has details on customizing that table.

I suggest not modifying this, however. Instead, as a workaround, you can add a new migration, delete whatever content is inside of the Up() method, and then update your database. This will update the history to match what you currently have.

However when you add the migration, you may want to review the code it produces first to see what EF thinks has changed. It might actually be a legitimate migration.

Edit: Schema changes are compared against hashes of your SSDL.

2
8/17/2018 4:08:19 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