Entity Framework - Start Over - Undo/Rollback All

2019-01-29 15:22发布

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.

4条回答
乱世女痞
3楼-- · 2019-01-29 15:56

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.

查看更多
混吃等死
4楼-- · 2019-01-29 16:07

For Entity Framework Core:

Update-Database -Migration:0
Remove-Migration
查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-29 16:10

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.

查看更多
登录 后发表回答