Изменения БД, влияющие на миграцию EF CodeFirst - PullRequest
0 голосов
/ 05 ноября 2019

У меня есть проект, который использует 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.

Я не уверен, как исправить эту ошибку, поскольку я не вносил постоянные изменения.

1 Ответ

0 голосов
/ 05 ноября 2019

Я понял это. Удалив FK FK_dbo.UserIndicatorPane_dbo.UserPane_ID и индекс в СУБД, я смог запустить update-database.

https://stackoverflow.com/a/42267673/802331

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...