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.
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.
For Entity Framework Core:
Update-Database -Migration:0
Remove-Migration
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.
Update-Database -Migration 0
Remove-Migration
The documentation is here: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#update-database and here: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#remove-migration
It is written wrong in their documentation i guess , for me i used
Update-Database -Target MigrationName
Success story sharing
enable-migrations
again. These are obviously helpful, but do they accomplish what the OP is asking for? (Please don't reply with "well, he accepted the answer." I'm trying to understand this, not be a smartass).enable-migrations
again and you are developing database from scratch you just need to follow the last sentence: delete database and all migration related code. If you started using migrations with existing database you first have to revert all migrations by using the second or third command, then deleteMigrationHistory
table and all migration related code. It should get you to starting position. You can also get starting database from backup (before using migrations) and delete all migration related code.-TargetMigration:0