在 PostgreSql 中获取“外键的引用和引用列的数量不一致”

Edd*_*nco 3 sql postgresql compiler-errors

我在 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);
Run Code Online (Sandbox Code Playgroud)

Eel*_*lke 6

当您在引用子句中未指定列列表时,它将扩展为被引用表的主键。

例如:

foreign key(rno) references Receipt
Run Code Online (Sandbox Code Playgroud)

扩展到

foreign key(rno) references Receipt(cid,rno)
Run Code Online (Sandbox Code Playgroud)

所以列数不​​匹配