create table buys (
user_id INT(11) not null,
software_id INT(11) not null,
associated_id INT(11) not null,
primary key (associated_id),
foreign key (software_id) references software,
foreign key (user_id) references users,
foreign key (associated_id) references associated);


我有一个具有总参与度和键约束的三元关系关联表,但是不能添加外键约束

最佳答案

检查以下查询:

CREATE TABLE products(
   prd_id int not null auto_increment primary key,
   cat_id int not null,
   FOREIGN KEY fk_cat(cat_id)
   REFERENCES categories(cat_id)
)ENGINE=InnoDB;


在您的情况下:

foreign key (software_id) references software -> here column name is missing in software table

关于mysql - 无法在MySQL中添加外键约束,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41634608/

10-12 01:13
查看更多