如何使用包管理器控制台 downgrade/rollback 在具有 Entity Framework 的通用 Windows 平台中迁移?

How to downgrade/rollback migration in Universal Windows Platform with Entity Framework using Package Manager Console?

我修改了model中的一个属性,结果是SQLite的版本不支持。这是错误。 {"SQLite does not support this migration operation ('DropColumnOperation'). For more information, see http://go.microsoft.com/fwlink/?LinkId=723262."}

所以我决定使用命令 Update-Database Migration "MyFirstMigration" 将其回滚,但控制台上显示错误 Update-Database shouldn't be used with Universal Windows Platform apps. Instead, call DbContext.Database.Migrate() at runtime.。推荐的这段代码已经是在生成上述第一个错误的应用程序的第一个 运行 处执行的代码。

我真的要绕圈子了。有人可以建议我如何 rollback/downgrade MySecondMigration ti MyFirstMigration?

Can someone suggest how I can rollback/downgrade MySecondMigration ti MyFirstMigration?

对于相同的 DbContext,只需在您的程序包管理器控制台上执行 Remove-Migration 命令,它将删除此 DbContext 的最后一次迁移。您的 MySecondMigration 将被删除,只剩下 MyFirstMigration

Update-Database shouldn't be used with Universal Windows Platform apps. Instead, call DbContext.Database.Migrate() at runtime

为此,正如此错误所示,DbContext.Database.Migrate() 将上下文的任何未决迁移应用到数据库,包括 Update-Database 所做的(将数据库更新为指定的迁移)。通过我这边的测试,对于相同的DbContext,每次新的迁移都是基于旧迁移的更新。 DbContext.Database.Migrate() 将应用所有迁移进行更新。如果您不想要最新的更新,只需将其删除即可回滚。