Entity Framework - Start Over - Undo/Rollback All Migrations

Entity FrameworkEntity Framework-4.3Entity Framework-Migrations

Entity Framework Problem Overview


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.

Entity Framework Solutions


Solution 1 - Entity Framework

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.

Solution 2 - Entity Framework

For Entity Framework Core:

Update-Database -Migration:0
Remove-Migration

Solution 3 - Entity Framework

To be clear, if using LocalDb, when you want to start from scratch just delete the database via the Database Explorer and then type enable-migrations -force in the Package Manager Console. Do not delete the database via the App_Data folder or you will have the following issue.

Solution 4 - Entity Framework

Solution 5 - Entity Framework

It is written wrong in their documentation i guess , for me i used

Update-Database -Target MigrationName

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondrzausView Question on Stackoverflow
Solution 1 - Entity FrameworkLadislav MrnkaView Answer on Stackoverflow
Solution 2 - Entity FrameworkAndrei KarcheuskiView Answer on Stackoverflow
Solution 3 - Entity FrameworkBrian OgdenView Answer on Stackoverflow
Solution 4 - Entity FrameworkSergeyView Answer on Stackoverflow
Solution 5 - Entity FrameworkSayed Muhammad IdreesView Answer on Stackoverflow