【Entity Framework】Revert the database to specified migration.
本文涉及的相关问题,如果你的问题或需求有与下面所述相似之处,请阅读本文
[Entity Framework] Revert the database to specified migration.
[Entity Framework] Re-scaffold migration file.
对于初期没有设计好Model的情况下, 已经add的migration并且已经update到db中之后可以通过下列命令达到重新编辑之前add的migration, 并且不会为你的项目新增migration文件.
比如我的项目已经有如下migration结构:
其中对于201901170814382_AddSlotManagement的migration,由于model模型变了我希望重新生成关于这个功能的migration.
首先将migration revert回到上一个migration
PM> Update-Database -TargetMigration 201901160836219_AddRelevanceModels
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Reverting migrations: [201901170814382_AddSlotManagement].
Reverting explicit migration: 201901170814382_AddSlotManagement.
然后重新执行add migration.记住名字一致和加上-Force参数
PM> Add-Migration 201901170814382_AddSlotManagement
Re-scaffolding migration '201901170814382_AddSlotManagement'.
Only the Designer Code for migration '201901170814382_AddSlotManagement' was re-scaffolded. To re-scaffold the entire migration, use the -Force parameter.
PM> Add-Migration 201901170814382_AddSlotManagement -Force
Re-scaffolding migration '201901170814382_AddSlotManagement'.