如何删除 Entity Framework Core 2.0 中的特定迁移?

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

我在包管理器控制台中使用 Add-Migration 和 运行 Update-DataBase 添加了大约 100 个迁移。现在我想删除比方说第 56 个数字迁移。我还没有找到任何方法来做到这一点。 EF Core 只允许我删除迁移序列,我认为这是正确的。因为如果我删除中间迁移,则以后的迁移可能会由于对旧迁移的依赖而失败。但如果没有依赖性,它应该允许我删除或禁用。

我知道我的问题可能无效,但我只是出于好奇。

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.

EF Core 不可能遍历每一次迁移并找出是否存在依赖关系,尤其是对于 SQL 语句。

如何删除特定迁移?

虽然有一个答案!

如果确定没有依赖,创建一个空迁移,然后将第56迁移中的"Up"和"Down"复制到对面("Down"和"Up") 的新迁移。

这也是 Git 所做的:要撤销旧提交,请创建一个执行相反操作的新提交。