![](/img/trans.png)
[英]I get an error in PostgreSql: number of referencing and referenced columns for foreign key disagree
[英]Getting “number of referencing and referenced columns for foreign key disagree” in PostgreSql
我在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)
所以列數不匹配
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.