我做错什么了?尝试在sqlfiddle中创建这些表不起作用。
Cannot add foreign key constraint
create table product (
pid int NOT NULL,
name varchar(10),
PRIMARY KEY (pid)
);
create table trans (
tid int NOT NULL ,
productId int NOT NULL,
userId int NOT NULL,
PRIMARY KEY (tid),
FOREIGN KEY (productId) REFERENCES product(pid),
FOREIGN KEY (userId) REFERENCES user1(uid)
);
create table user1 (
uid int NOT NULL ,
location varchar(22),
PRIMARY KEY (uid)
);发布于 2016-09-23 02:04:00
正如@BillKarwin所提到的,包含trans表引用的主键的表的定义应该出现在trans表的定义之前。因此,您应该将trans表的定义移动到最后。
但是,即使这样做也会导致SQLFiddle中的一个错误:
SQLFiddle (取消trans中的外键引用)
SQLFiddle在接受这个表模式时似乎遇到了一些问题。这并不奇怪,因为该网站似乎经常有这样的问题。
https://stackoverflow.com/questions/39651364
复制相似问题