Я пытаюсь вставить в таблицу «ProjectCategoryRelationship» и получаю сообщение об ошибке ограничения внешнего ключа. Я ценю любую помощь или подсказку.
Project, Category, ProjectCategory Таблицы отношений:
CREATE TABLE "Project" (
"Id" INTEGER NOT NULL CONSTRAINT "PK_Project" PRIMARY KEY AUTOINCREMENT,
"Title" varchar(256) NULL,
"Description" text NULL,
"UserId" INTEGER NULL,
"CreatedOn" TEXT NOT NULL,
CONSTRAINT "FK_Project_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
)
CREATE TABLE "Category" (
"Id" INTEGER NOT NULL CONSTRAINT "PK_Category" PRIMARY KEY AUTOINCREMENT,
"Name" varchar(256) NULL
)
CREATE TABLE "ProjectCategoryRelationship" (
"ProjectId" INTEGER NOT NULL,
"CategoryId" INTEGER NOT NULL,
"Id" INTEGER NOT NULL,
CONSTRAINT "PK_ProjectCategoryRelationship" PRIMARY KEY ("ProjectId", "CategoryId"),
CONSTRAINT "FK_ProjectCategoryRelationship_Category_CategoryId" FOREIGN KEY ("CategoryId") REFERENCES "Category" ("Id") ON DELETE CASCADE,
CONSTRAINT "FK_ProjectCategoryRelationship_Project_CategoryId" FOREIGN KEY ("CategoryId") REFERENCES "Project" ("Id") ON DELETE CASCADE
)
Есть категория с Id 1:
> SELECT * from Category
Id Name
1 java
Есть Проект с идентификатором 5:
> SELECT * from Project
Id Title Description UserId CreatedOn
5 Title Description 1 0001-01-01 00:00:00+00:00
Ошибка вставки новой строки в ProjectCategoryRelationship:
INSERT INTO "main"."ProjectCategoryRelationship"
("ProjectId", "CategoryId", "Id")
VALUES (5, 1, 1);
Result: FOREIGN KEY constraint failed
At line 1:
INSERT INTO "main"."ProjectCategoryRelationship"
("ProjectId", "CategoryId", "Id")
VALUES (5, 1, 1);