个人建网站怎么赚钱,网站分析论文,安徽金路建设集团有限公司网站,深圳网站制作公司平台场景描述#xff1a;项目中存在两个迁移 Teacher 和 TeachingPlan #xff0c;TeachingPlan 在 Teacher 之后创建#xff0c;并且已经执行 dotnet ef database update 将新迁移应用到数据库。此时#xff0c;因为实体修改#xff0c;我们希望删除 TeachingPlan 迁移然后创… 场景描述项目中存在两个迁移 Teacher 和 TeachingPlan TeachingPlan 在 Teacher 之后创建并且已经执行 dotnet ef database update 将新迁移应用到数据库。此时因为实体修改我们希望删除 TeachingPlan 迁移然后创建新的 TeachingPlan 迁移该怎么办示例查看迁移列表dotnet ef migrations list
Build started...
Build succeeded.
20211026071835_Teacher
20211108141706_TeachingPlan分析直接移除 TeachingPlan 行不行我们先试试。示例移除最后一个迁移dotnet ef migrations remove
Build started...
Build succeeded.
The migration 20211108141706_TeachingPlan 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.移除失败迁移已经应用到数据库。如果该迁移已经应用于其他数据库请考虑用一个新的迁移来恢复其变化。根据错误提示建议我们再创建一个新的迁移比如TeachingPlan_01 这样能够达到效果但是不够简洁存在多个作用相同的迁移。重新梳理思路在移除迁移之前先将数据库恢复到数据迁移之前的状态。使用 dotnet ef database update [miagration_anme] 可以将数据库架构恢复到指定迁移时的状态。示例将数据库恢复到 Teacherdotnet ef database update Teacher然后移除 TeachingPlan 迁移dotnet ef migrations remove移除成功此时迁移和数据库结构都恢复到 Teacher 状态再重新创建迁移dotnet ef migrations add TeachingPlan迁移回退任务完成小结•迁移具有前后连贯性迁移和数据架构应保持一致性。应避免删除已应用到生产数据库的任何迁移。•dotnet ef migrations remove 不带参数每执行一次则移除最新创建的迁移。•dotnet ef database update 可以将数据库更新到任何一个指定迁移时的架构。