3

I am using Pomelo Entity Franework Core MySql Provider and I have scaffolded a migration, that drops an index in a MySql database. It looks this

public partial class IndexUpdate : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropIndex(
            name: "IX_Buildings_AddressId",
            table: "Buildings");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateIndex(
            name: "IX_Buildings_AddressId",
            table: "Buildings",
            column: "AddressId",
            unique: true);
    }
}

The database contains this index and it has a type of UNIQUE. When I conduct the migration an error occurs with the following message:

Cannot drop index 'IX_Buildings_AddressId': needed in a foreign key constraint

I fully understand that it is a basic sql drop index operation, I have found this solution. My question is: is there a way not to drop and create a foreign key in order to drop index? I would prefer to resolve the problem in terms of Entity Framework/MySql provider rather than raw Sql

  • 1
    Check some of the less upvoted answers from the linked SO question and you will find your answer :) Recap: create another index that can be used by the FK and then drop the index you want. – Shadow Jul 17 '17 at 16:42
  • @Shadow I would like to resolve the issue using .net rather than sql – Eugen Bondarenko Jul 18 '17 at 07:11
  • 1
    Then create another index from asp.net before dropping the one in the question. – Shadow Jul 18 '17 at 07:42

0 Answers0