Introducing FOREIGN KEY constraint 'FK_books_subCategories_SubCategoryId' on table 'books' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
What I have tried:
migrationBuilder.CreateTable(
name: "subCategories",
columns: table => new
{
Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "(newid())"),
Name = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false),
CategoryId = table.Column(type: "uniqueidentifier", nullable: false),
CurrentStaut = table.Column(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_subCategories", x => x.Id);
table.ForeignKey(
name: "FK_subCategories_categories_CategoryId",
column: x => x.CategoryId,
principalTable: "categories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "books",
columns: table => new
{
Id = table.Column(type: "uniqueidentifier", nullable: false, defaultValueSql: "(newid())"),
Name = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false),
Author = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false),
ImageName = table.Column(type: "nvarchar(max)", nullable: false),
FileName = table.Column(type: "nvarchar(max)", nullable: false),
Description = table.Column(type: "nvarchar(max)", nullable: false),
Publish = table.Column(type: "bit", nullable: false),
CategoryId = table.Column(type: "uniqueidentifier", nullable: false),
SubCategoryId = table.Column(type: "uniqueidentifier", nullable: false),
CurrentStaut = table.Column(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_books", x => x.Id);
table.ForeignKey(
name: "FK_books_categories_CategoryId",
column: x => x.CategoryId,
principalTable: "categories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_books_subCategories_SubCategoryId",
column: x => x.SubCategoryId,
principalTable: "subCategories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});