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)
-
0
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.
-
0
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