'Removing foreign key in migration fires twice

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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source