我有以下代码,它会引发错误:
错误:没有与引用表“person”的给定键匹配的唯一约束
DROP TABLE IF EXISTS person;
CREATE TABLE person (
sn serial PRIMARY KEY,
id int NOT NULL,
modified timestamp,
name text
);
CREATE UNIQUE INDEX person_id_key ON person (id) WHERE modified IS NULL;
DROP TABLE IF EXISTS account;
CREATE TABLE account (
id int NOT NULL REFERENCES person(id),
name text
);
有一个唯一索引id
:
Table "public.person"
Column | Type | Collation | Nullable | Default
----------+-----------------------------+-----------+----------+------------------------------------
sn | integer | | not null | nextval('person_sn_seq'::regclass)
id | integer | | not null |
modified | timestamp without time zone | | |
name | text | | |
Indexes:
"person_pkey" PRIMARY KEY, btree (sn)
"person_id_key" UNIQUE, btree (id) WHERE modified IS NULL
为什么外键不够?