У меня есть проект, который использует EF Code First. Я изменил свою базу данных внутри СУБД, изменив несколько ограничений на «каскад удаления», и сразу же отменил изменения.
Когда я запустил свой код, я получил эту ошибку: 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.
Я не уверен, как исправить эту ошибку, поскольку я не вносил постоянные изменения.