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?
Asked
Active
Viewed 2.1k times
5 Answers
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
-
What if this is the first migration which I have applied on my database. How revert these changes? – Himalaya Garg Jun 05 '19 at 07:40
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"

siddhartha sharma
- 21
- 1
- 6
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

Jakob Ladingkaer
- 61
- 1
- 5
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