1

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

But what in the code does it compare the contents of this table to?
it is the difference between the ModelSnapshot and your migrations files that determines if your database is out of date
Your migrations files are not checked. EF constructs a hash based on your schema. learn.microsoft.com/en-us/dotnet/framework/data/adonet/ef/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.