我有3個表:CD
,Song
和Song_Details
這是CD
& Song
之間的關係:MySQL的外鍵問題
create table Song(
ID int not null auto_increment,
Title varchar(255) not null,
Length float not null,
primary key (ID, Title)
);
create table CD(
Title varchar(255) not null,
CD_Number int not null,
primary key (Title, CD_Number)
);
Create table Song_Details(
CD_Title varchar(255) not null,
Song_Title varchar(255) not null,
Track_Number int not null,
primary key(CD_Title, Song_Title),
foreign key(CD_Title) references CD(Title),
foreign key(Song_Title) references Song(Title)
);
我設法找到了這條線在Song_Details
:
foreign key(Song_Title) references Song(Title)
是拋Error 1215(HY000): Cannot add foreign key constraint;
任何人都可以幫助我看到基於米Ÿ表,可能會導致此問題?
請閱讀http://stackoverflow.com/questions/15534977/mysql-cannot-add-foreign-key-constraint中的答案以獲取故障診斷提示。 –
在參考表中找不到索引,其中 引用列顯示爲第一列,或表中的列類型 與引用的表不匹配約束。 – barudo