26

I have been changing my domain classes and executed Update-Database in the Package Manager Console, After i realized that need to add an index and need to down-grade to the previous state. what is the proper command to down-grade one step in migration?

Ehsan Zargar Ershadi
  • 24,115
  • 17
  • 65
  • 95

5 Answers5

38

Update-Database has a TargetMigration parameter that you can use to update to a particular migration. You can use that to upgrade or downgrade.

Update-Database –TargetMigration PreviousMigrationName
Matt Ward
  • 47,057
  • 5
  • 93
  • 94
6

For Entity Framework Core ONLY and if you are using it from Package Manager

Update-Database –Migration yourMigrationName
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
2
Update-Database –TargetMigration "lastcreatedMigrationName"

example:

update-database -targetmigration: "entity-logs-index"
2

If you want to rollback all migrations you can use (Stolen from this answer):

Update-Database -TargetMigration:0

But in EF Core it is

Update-Database -Migration:0
0

To continue this, if you have outstanding model changes i do believe this will fail. This can be frustrating when you already have code in place.

Update-Database –TargetMigration "targetmigrationname" -force

If you use this command and include the force flag the database will migrate to that version regardless of having outstanding model changes.

kmacdonald
  • 3,381
  • 2
  • 18
  • 22