#Dotnet EF Core migration issue Foreign key constraint is incorrectly formed

0

While executing migration on the server (working proper on local) I am having the issue:

Can't create table hive.ApiaryHives (errno: 150 "Foreign key constraint is incorrectly formed") ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Can't create table hive.ApiaryHives (errno: 150 "Foreign key constraint is incorrectly formed")

Here is my migration file :

protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
                        name: "ApiaryHives",
                        columns: table => new
                        {
                            ApiaryID = table.Column<int>(nullable: false),
                            HiveID = table.Column<int>(nullable: false)
                        },
                        constraints: table =>
                        {
                            table.PrimaryKey("PK_ApiaryHives", x => new { x.ApiaryID, x.HiveID });

                            table.ForeignKey(
                            name: "FK_ApiaryHives_Apiary_ApiaryID",
                            column: x => x.ApiaryID,
                            principalTable: "Apiary",
                            principalColumn: "ID",
                            onDelete: ReferentialAction.Cascade);

                            table.ForeignKey(
                            name: "FK_ApiaryHives_ApHives_HiveID",
                            column: x => x.HiveID,
                            principalTable: "ApHives",
                            principalColumn: "ID",
                            onDelete: ReferentialAction.Cascade);
                        });
    }

Error screenshot

c#
mysql
.net
foreign-keys
migration
asked on Stack Overflow Jul 25, 2019 by Mahesh S • edited Jul 25, 2019 by Pavel Anikhouski

1 Answer

0

Everything was fine other than my table name, that contains (s) postfix while creating the reference.

answered on Stack Overflow Jul 27, 2019 by Mahesh S

User contributions licensed under CC BY-SA 3.0