欢迎光临
个人技术文档整理

Remove-Migration迁移已经应用到数据库,如何进行迁移回退操作?

Remove-Migration 迁移已经应用到数据库,如何进行迁移回退操作?

Remove-Migration:只能删除 未应用 到数据库的脚本 

 

场景描述:当我们把迁移脚本  应用到数据库后:

移除失败:迁移'20221007081333 v2'已经应用到数据库。恢复后再试一次。如果迁移已应用到其他数据库,请考虑使用新的迁移来恢复其更改。

PM> Remove-Migration
Build started...
Build succeeded.
The migration '20221007081333_v2' has already been applied to the database. Revert it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration instead.
PM> 

解決方案:

方式一:

  • 将数据库中 【__EFMigrationsHistory】表中的 '20221007081333_v2' 记录删除
  • 然后使用  Remove-Migration  移除脚本

方式二:

  • 使用 Update-Database 'v1' 直接回滚上一个版本
  • 然后使用  Remove-Migration  移除脚本

 

赞(1)