Reset Entity-Framework Migrations

Todd picture Todd · Jul 27, 2012 · Viewed 204.2k times · Source

I've mucked up my migrations, I used IgnoreChanges on the initial migration, but now I want to delete all my migrations and start with an initial migration with all of the logic.

When I delete the migrations in the folder and try and Add-Migration it doesn't generate a full file (it's empty - because I haven't made any changes since my last, but now deleted, migration).

Is there any Disable-Migrations command, so I can rerun Enable-Migrations?

Answer

Todd picture Todd · Jul 27, 2012

You need to :

  1. Delete the state: Delete the migrations folder in your project; And
  2. Delete the __MigrationHistory table in your database (may be under system tables); Then
  3. Run the following command in the Package Manager Console:

    Enable-Migrations -EnableAutomaticMigrations -Force
    

    Use with or without -EnableAutomaticMigrations

  4. And finally, you can run:

    Add-Migration Initial