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!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>