简体   繁体   English

实体框架核心删除迁移问题

[英]Entity Framework Core remove-migration problem

I have some changes to rescaffold my tables and create a migration named X . 我进行了一些更改以重新折叠表并创建名为X的迁移。 I try to apply X via update-migration but I have an exception about some of default data. 我尝试通过update-migration应用X,但是我对某些默认数据有例外。 My X migration is not in __EFMigrationHistory table because of the exception. 由于异常,我的X迁移不在__EFMigrationHistory表中。 However, when I run remove-migration command to remove X migration, dotnet try to run Down function in X . 但是,当我运行remove-migration命令删除X迁移时,dotnet尝试在X运行Down函数。 I couldn't understand why this happened. 我不明白为什么会这样。 I want to use remove-migration because to edit ModelSnapshot.cs file is hard manually. 我要使用remove-migration因为手动编辑ModelSnapshot.cs文件很困难。 Is there anyone who knows the reason? 有谁知道原因吗?

I've found a solution. 我找到了解决方案。 If the migration has a script related HasData function ( InsertData() , UpdateData() or DeleteData() , that causes a trouble when you want to run remove-migration. I uncommented those lines and removed the last migration successfully. 如果迁移具有脚本相关的HasData函数( InsertData()UpdateData()DeleteData() ,则在您要运行remove-migration时会引起麻烦。我取消注释了这些行,并成功删除了上一次迁移。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM