使用相同的数据库更新数据库后,是否可以删除 EF Core 数据库迁移?

使用相同的数据库更新数据库后,是否可以删除 EF Core 数据库迁移?

问题描述:

在 .NET EF 核心中,是否可以在通过Update-database"更新数据库后删除/恢复数据库迁移?命令?

In .NET EF core, Is it possible to remove/revert a Database migration after the database is updated by "Update-database" command?

是的,这是可能的,但前提是它是最后一次迁移,或者您在它之后恢复所有迁移.

Yes, it's possible, but only if it is the last migration or if you revert all migrations after it.

要恢复所有迁移,包括所需的迁移,请使用 -Migration 相同Update-Database 命令的参数,并在之前传递所需的迁移名称/ID(或特殊值0 如果是第一个)

To revert all migrations including the desired, use the -Migration parameter of the same Update-Database command and pass the name/id of the migration before the desired (or special value 0 if it is the first)

Update-Database MigrationBeforeTheOneYouWantToRevert

有关详细信息,请参阅应用迁移 - 命令行工具部分.

For more info, see Applying Migrations - Command-line tools sections of the official EF Core documentation.