0

Rollingback to a specific migration(C) means rollingback all the migrations in between (G,F,D,E). Is their a way where we can rollback only rollback migration c and not effect the other migrations .

I have also looked at other questions aiming on this topic but dint get a hint of such mechanism.

EF Migrations: Rollback last applied migration?

Arun3x3
  • 193
  • 1
  • 7
  • 17

1 Answers1

0

It does depend on the changes, but if the changes in migration C are independent of D - G changes you can do this:

  1. Add new Migration H.
  2. Copy the Down() code from C to the Up() code of H.
  3. Copy the Up() code from C to the Down() code of H.
  4. update-database

Another option is to just undo the model changes in code and the next migration will reverse them.

If the deployed databases all have those migrations applied you could do this:

  1. Rollback to migration B (update-database -TargetMigration B).
  2. Delete migrations C - G in code and in __MigrationHistory table.
  3. Add a new migration C. This will now include all the changes to get the database up to date (formerly D - G).
  4. update-database

The key thing to remember is that migrations will look at the last code migration for a model then compare that to what your code models are now. For more info see here.

Steve Greene
  • 12,029
  • 1
  • 33
  • 54