Entity Framework code first migration
Migration is one of the key features of Entity Framework and you strongly need it when you’re developing in “Code-First” style which is my favorite. From time to time however, it may irritate you by throwing exceptions.
- Install Entity Framework
- Issue Enable-Migration command in Console Manager
- Set “AutomaticMigrationsEnabled” in your configuration file (created by Enable-Migration command) to “True”.
- Issue Update-Database command in Console Manager
Troubleshooting Entity Framework Migration
Troubleshooting process is actually straightforward but it may take time till you figure it how. Just follow these steps if you run to any problems:
- Delete Data in tables which have been changed
- Delete all the tables (including _MigrationHistory table) if previous step does not solve your problem.
- Delete the Database if previous step does not solve your problem.
If you have all of your Data in the “Seed” method then just do the last step – Delete the database.