sql - 影响 EF CodeFirst 迁移的数据库更改
问题描述
我有一个使用 EF Code First 的项目。我通过将一些约束更改为“删除级联”来更改 DBMS 中的数据库,然后我立即撤消了更改。
当我运行我的代码时,我得到了这个错误:Unable to update database to match the current model because there are pending changes and automatic migration is disabled.
所以我运行了add-migration newconstraints
它并生成了迁移文件。
DropForeignKey("dbo.UserPane", "ID", "dbo.UserIndicatorPane");
DropForeignKey("dbo.UserAxisPane", "ID", "dbo.UserPane");
DropForeignKey("dbo.UserPaneProperty", "UserPaneID", "dbo.UserPane");
DropForeignKey("dbo.UserIndicator", "UserIndicatorPaneID", "dbo.UserIndicatorPane");
DropIndex("dbo.UserPane", new[] { "ID" });
DropPrimaryKey("dbo.UserPane");
DropPrimaryKey("dbo.UserIndicatorPane");
AlterColumn("dbo.UserPane", "ID", c => c.Int(nullable: false, identity: true));
AlterColumn("dbo.UserIndicatorPane", "ID", c => c.Int(nullable: false));
AddPrimaryKey("dbo.UserPane", "ID");
AddPrimaryKey("dbo.UserIndicatorPane", "ID");
CreateIndex("dbo.UserIndicatorPane", "ID");
AddForeignKey("dbo.UserIndicatorPane", "ID", "dbo.UserPane", "ID");
AddForeignKey("dbo.UserAxisPane", "ID", "dbo.UserPane", "ID");
AddForeignKey("dbo.UserPaneProperty", "UserPaneID", "dbo.UserPane", "ID", cascadeDelete: true);
AddForeignKey("dbo.UserIndicator", "UserIndicatorPaneID", "dbo.UserIndicatorPane", "ID", cascadeDelete: true);
现在update-database
给我这个错误:The constraint 'PK_dbo.UserPane' is being referenced by table 'UserIndicatorPane', foreign key constraint 'FK_dbo.UserIndicatorPane_dbo.UserPane_ID'.
Could not drop constraint. See previous errors.
我不确定如何修复此错误,因为我没有进行任何永久性更改。
解决方案
我想到了。通过删除 FKFK_dbo.UserIndicatorPane_dbo.UserPane_ID
和 DBMS 中的索引,我能够运行更新数据库。
推荐阅读
- php - 不能在路由中使用带保护的多身份验证中间件
- c# - C# grpc 服务器端唯一证书
- c - cs50 过滤器(模糊)分配(pset4)(已解决!)
- .htaccess - 如何将 /page/ 重定向到 page.html
- scala - PySpark 将 Dataframe 作为额外参数传递给映射
- java - Collection.reverse() 方法不适用于 Integer ArrayList
- stripe-payments - 从当月的第一个日期开始的条带订阅,初始费用
- java - 如何开发自定义 SonarQube 插件?
- c++ - std::shared_ptr
显示到文本浏览器? - .net - 使用反射 VB.NET 调用具有自定义类型参数的函数