Oct 25

Synchronising Code First Entity Framework database with existing database

Suppose you have an existing Entity Framework database in production and you’ve made changes to the model in your C# project. Of course you have messed up / lost your migrations files. What to do?

– delete the _MigrationHistory table from the database

– delete the Migrations folder from you solution (you might want to keep a backup of the Configurations.cs file is you’ve made changes to that e.g. Seed)

– in the package manager console type:

  1. enable-migrations
  2. add-migration initialcreate -ignorechanges
  3. update-database

Your all set!