in entity framework

Entity Framework – reset migrations

tl;tr; How to reset migrations in Entity framework, and start with raw database

While I was working at the project for Imagine Cup. I came across to one major problem. What if I want to delete all migrations and start over with raw migration (but at same database). In my case it was due to one of my update-database, it doesn’t run correctly, some sort of error I couldn’t figure out, how to fix. I decited to start with raw migrations.

  1. First of all, you have to type this commandn “Update-Database -TargetMigration:0 -Force” (in Package Manager Console) it wipe out all your changes at db but models stays in it current state.
  2. Then you have to delete Migrations folder
  3. Delete __MIgrationHistory at your database it can be located in SystemTables
  4. and all others tables in traget db.
  5. (Please keep the order of steps, because if you delete first migrations folder, it’s over make new project…)

After all these steps, now we can start do your raw migration “Enable-Migration” if there is need, use “Enable-Migration -Force”. Visit here to learn how to migrate.