Search code examples
entity-frameworkentity-framework-4.3entity-framework-migrations

Entity Framework - Start Over - Undo/Rollback All Migrations


For some reason, my migrations appear to have been jumbled/corrupted/whatever. I'm at the point where I just want to start over, so is there a way to completely undo all migrations, erase the history, and delete the migration code, so I'm back to square one?

e.g.) PM> Disable-Migrations or Rollback-Migrations

I don't want to "update" to an original migration step (i.e. something like an InitialSchema target) because I can't find it anymore.


Solution

  • You can rollback to any migration by using:

    Update-Database -TargetMigration:"MigrationName"
    

    If you want to rollback all migrations you can use:

    Update-Database -TargetMigration:0
    

    or equivalent:

    Update-Database -TargetMigration:$InitialDatabase 
    

    In some cases you can also delete database and all migration classes.