Entity-framework – Reset Entity-Framework Migrations


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?

Best Solution

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