删除迁移中的外键会引发两次

发布于 2025-01-13 21:00:50 字数 523 浏览 3 评论 0原文

我正在尝试迁移 ASP.NET Core 6 + Entity Framework Core 项目。

迁移时,必须删除表的外键。

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropForeignKey(
    name: "FK_Clients_Company",
    table: "Clients");
}

Database.Migrate() 上下文构造函数中调用时,出现错误:

“FK_Clients_Company”不是约束。无法删除约束

同时,密钥本身可用(包括通过 sysobjects 中的请求定位)并被删除,事实证明 DropForeignKey 删除后第二次工作,但找不到密钥。

在其他任何地方都不会使用此键执行其他操作。

I'm trying to make a migration for an ASP.NET Core 6 + Entity Framework Core project.

In the migration, the foreign key of the table must be removed.

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropForeignKey(
    name: "FK_Clients_Company",
    table: "Clients");
}

When calling in the Database.Migrate() context constructor, I get an error:

'FK_Clients_Company' is not a constraint. Could not drop constraint

At the same time, the key itself is available (including is located by a request in sysobjects) and is deleted, it turns out that
DropForeignKey works 2nd time after deletion and does not find the key.

No other manipulations are performed with this key anywhere else.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文