Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to remove a particular migration? #4620


User avatar
0
manojreddy created

I have added around 100 migrations using Add-Migration in Package Manager Console and run Update-DataBase. Now I want to remove let's say 56th number migration. I have not found any way to do this. EF Core allows me to remove migrations sequences only, which is I think correct. because If I remove an in-between migration, later migration might fail due to dependency on old migrations. But If there is no dependency it should allow me to remove or disable.

I know my question can be invalid, But I'm asking just for the curiosity.


2 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    EF Core allows me to remove migrations sequences only, which is I think correct. because If I remove an in-between migration, later migration might fail due to dependency on old migrations.

    Exactly.

    But If there is no dependency it should allow me to remove or disable.

    It's infeasible for EF Core to go through every migration and figure out if there is a dependency, especially for SQL statements.

    How to remove a particular migration?

    There's an answer to this though! If you are sure there is no dependency, create an empty migration, then copy the "Up" and "Down" in the 56th migration into the opposite ("Down" and "Up") of the new migration. This is what Git does too: to reverse an old commit, create a new commit that does the opposite.

  • User Avatar
    0
    manojreddy created

    Awesome, Thanks a lot

    create an empty migration, then copy the "Up" and "Down" in the 56th migration into the opposite ("Down" and "Up") of the new migration

    Thanks for this tip, You rock