2017-01-13 81 views
0
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); 

我有全員參與,一鍵約束的三元關係,關聯表,但不能添加外鍵約束不能在mysql中添加外鍵約束

+0

你的錯誤是什麼? –

+0

這些表具有指定的列作爲主鍵? – jarlh

+3

您的外鍵僅提及引用的表格,而不是屬性。它應該像'外鍵(software_id)引用軟件(id)' – HoneyBadger

回答

0

檢查以下查詢:

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