只是好奇,如果我有这张桌子:
CREATE TABLE "post" (
"id" SERIAL,
"revision" INTEGER NOT NULL DEFAULT 0,
"summary" CHARACTER VARYING NOT NULL,
"description" TEXT NOT NULL,
"user_id" INTEGER NOT NULL
REFERENCES "user" ("id") MATCH FULL
ON UPDATE CASCADE
ON DELETE RESTRICT,
"post_type_id" INTEGER NOT NULL
REFERENCES "post_type" ("id") MATCH FULL
ON UPDATE CASCADE
ON DELETE RESTRICT,
"ctime" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
PRIMARY KEY("id", "revision")
);
存储帖子,这个表:
CREATE TABLE "post_state" (
"post_id" INTEGER NOT NULL,
"assembly_seat_id" INTEGER NOT NULL
REFERENCES "assembly_seat" ("id") MATCH FULL
ON UPDATE CASCADE
ON DELETE RESTRICT,
PRIMARY KEY("post_id")
);
我希望我的post_id
领域指向post(id)
,我该怎么做?我尝试过使用以下短语:
"post_id" INTEGER NOT NULL UNIQUE,
REFERENCES "post" ("id") MATCH SIMPLE
ON UPDATE RESTRICT
ON DELETE RESTRICT,
但我收到此错误:
错误:引用表“post”的给定键没有唯一约束匹配
在这种情况下, 的值post_state(asembly_seat_id)
不会改变。