下面的示例表Stream_types给出了一个错误:没有唯一约束匹配给定引用表的键,并且已经盯着它,而现在我无法弄清楚在这种情况下出现此错误的原因。
create table Stream_types (
id integer NOT NULL,
career careertype NOT NULL,
code character(1) NOT NULL,
description shortstring NOT NULL
);
create table Streams (
id integer, -- PG: serial
code char(6) not null, -- e.g. COMPA1, SENGA1
name LongName not null,
offeredBy integer references OrgUnits(id),
stype ShortString references Stream_types(id),
description TextString,
firstOffer integer references Semesters(id), -- should be not null
lastOffer integer references Semesters(id), -- null means current
primary key (id)
);
错误是:
ERROR: there is no unique constraint matching given keys for referenced table "stream_types"
********** Error **********
ERROR: there is no unique constraint matching given keys for referenced table "stream_types"
SQL state: 42830
我使用postgresql 9.3.16,有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
更改create table Stream_types语句,如下所示:
create table Stream_types (
id integer NOT NULL PRIMARY KEY,
career careertype NOT NULL,
code character(1) NOT NULL,
description shortstring NOT NULL
);