Entity Framework - Start Over - Undo/Rollback All Migrations

后端 未结 5 637
忘了有多久
忘了有多久 2020-12-12 09:18

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 m

相关标签:
5条回答
  • 2020-12-12 09:45

    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.

    0 讨论(0)
  • 2020-12-12 09:45

    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.

    0 讨论(0)
  • 2020-12-12 09:55

    For Entity Framework Core:

    Update-Database -Migration:0
    Remove-Migration
    
    0 讨论(0)
  • 2020-12-12 09:56
    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

    0 讨论(0)
  • 2020-12-12 10:05

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

    Update-Database -Target MigrationName
    
    0 讨论(0)
提交回复
热议问题