How to remove a particular migration in Entity Framework Core 2.0?

asp.net-core c# ef-code-first entity-framework entity-framework-core

Question

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.

1
2
2/3/2018 5:13:33 AM

Accepted Answer

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.

2
2/3/2018 10:55:04 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow