PostgreSQL约束错误

时间:2015-11-23 12:02:59

标签: sql postgresql foreign-keys

我遇到此错误:

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

Postgresql constraint

What is causing ERROR: there is no unique constraint matching given keys for referenced table?

我希望有人可以帮助我。我非常喜欢postgres,并且不完全理解外键是如何工作的。

干杯

0 个答案:

没有答案