我在pgAdmin 4中创建了一些表,但是由于某种原因,我一直收到错误消息标题,您能找出原因吗?我没有发现任何问题,我已经研究了与我的代码类似的完美编译的示例代码。它也可以在IDEone(http://ideone.com/ZBn2Nr)中运行。
谢谢!
Create table item
(iname varchar(30) primary key,
itype varchar(30));
Create table Cafe
(license numeric(5,0) primary key,
cname varchar(30),
address varchar(30));
Create table Client
(cid numeric(5,0) primary key,
name varchar(30),
phone numeric(9,0));
Create table Likes
(cid numeric(5,0),
iname varchar(30),
primary key(cid,iname),
foreign key(cid) references Client,
foreign key(iname) references item);
Create table Sells
(license numeric(5,0),
iname varchar(30),
price float check(price > 0),
primary key(license,iname),
foreign key(license) references Cafe,
foreign key(iname) references item);
Create table Receipt
(cid numeric(5,0),
rno numeric(5,0),
license numeric(5,0),
rdate date,
primary key(cid,rno),
foreign key(cid) references Client,
foreign key(license) references Cafe);
Create table Buys
(cid numeric(5,0),
rno numeric(5,0),
iname varchar(30),
amount int check(amount > 0),
primary key(cid,rno,iname),
foreign key(cid) references Client,
foreign key(rno) references Receipt,
foreign key(iname) references item);
最佳答案
如果您在references子句中未指定列列表,它将扩展为被引用表的主键。
例如:
foreign key(rno) references Receipt
扩展到
foreign key(rno) references Receipt(cid,rno)
所以列数不匹配
关于sql - 在PostgreSQL中获取 “number of referencing and referenced columns for foreign key disagree”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45346269/