我遇到此错误:
ERROR: there is no unique constraint matching given keys for referenced table "vulling"
这是我制作外键的代码:
ALTER TABLE put_25_vlak_1_spoor
ADD FOREIGN KEY (spoor,vulling)
REFERENCES vulling(spoor,vulling);
这些表是这样制作的:
CREATE TABLE put_25_vlak_1_spoor
(
id serial NOT NULL,
geometry_spoor geometry(MultiPolygon,28992),
spoor integer NOT NULL,
put integer,
vlak integer,
vulling integer NOT NULL,
CONSTRAINT put_25_vlak_1_spoor_pkey PRIMARY KEY (spoor, vulling)
)
CREATE TABLE vulling
(
vlak smallint,
textuur character varying(8),
vulling integer NOT NULL,
spoor integer NOT NULL,
put integer NOT NULL,
CONSTRAINT vulling_pkey PRIMARY KEY (vulling, put, spoor)
)
我在stackoverflow上阅读了这些主题,但我并不完全理解他们的意思:
PostgreSQL constraint problems
What is causing ERROR: there is no unique constraint matching given keys for referenced table?
我希望有人可以帮助我。我非常喜欢postgres,并且不完全理解外键是如何工作的。
干杯