3
我有journal
如何將外鍵設置爲一個有序的id
CREATE TABLE "public"."journal" (
"id" "public"."inc_journal" NOT NULL,
"short_desc" varchar(20),
"description" varchar(1000),
"default_gl_account_id" int8,
"company_id" int2,
"creator_user_id" int4,
"created_date" timestamp(6),
"type" "public"."journal_type",
CONSTRAINT "journal_pkey" PRIMARY KEY ("id")
)
WITH (OIDS=FALSE)
;
爲inc_journal的畫質下表的定義是這樣的序列,像這樣:
CREATE SEQUENCE "public"."inc_journal"
INCREMENT 1
MINVALUE 1
MAXVALUE 4294967295
START 1
CACHE 1;
我想設置一個外鍵像這樣:
ALTER TABLE "public"."entry"
ADD FOREIGN KEY ("journal_id") REFERENCES "public"."journal" ("id");
但是,當我這樣做時,我得到一個錯誤:
[Err] ERROR: foreign key constraint "entry_journal_id_fkey" cannot be implemented
DETAIL: Key columns "journal_id" and "id" are of incompatible types: integer and inc_journal.
我該如何擺脫這個錯誤?
是否需要設置journal_id
才能輸入inc_journal
?我想仍然插入null
到現場,所以這似乎不是正確的選擇。
+1這很有意義,來自MySQL,所以我對付了一點學習曲線。 – Johan