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