Asp.Net核心实体框架迁移错误:外键约束中需要的索引

时间:2017-07-17 16:15:15

标签: c# mysql entity-framework asp.net-core ef-migrations

我正在使用Pomelo Entity Franework Core MySql Provider,我已经建立了一个迁移,它在MySql数据库中删除了一个索引。看起来这个

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);
    }
}

数据库包含此索引,其类型为UNIQUE。当我进行迁移时,会出现以下消息的错误:

无法在外键约束中删除索引和IX_Buildings_AddressId'

我完全理解这是一个基本的sql drop index操作,我找到了这个solution。我的问题是:有没有办法不放弃并创建外键以降低索引?我更愿意在Entity Framework / MySql提供程序而不是原始Sql

方面解决问题

0 个答案:

没有答案
相关问题