我正在研究一個類項目的音樂數據庫,並且遇到了爲某些表設置外鍵的問題。MySQL中的MusicDB對同一個表的多個外鍵
我有大約6張桌子。
Songs
Artist
FeaturedArtist
Albums
Genres
SubGenres
RelatedGenres
RecordLabel
的問題都圍繞着以下表格
create table Songs(Title varchar(75) not null, Artist varchar(40) not null, FeaturedArtist varchar(100),
Album varchar(100), SongYear YEAR(4) not null, Genre char(10) not null, SubGenre varchar(30), Producer varchar(30) not null,
SongWriter varchar(50), MusicVideo varchar(30000), Lyrics varchar(30000) not null,
PRIMARY KEY (Title),
FOREIGN KEY(Artist) REFERENCES Artist(Artist),
FOREIGN KEY(FeaturedArtist) REFERENCES FeaturedArtists(Artist),
FOREIGN KEY(Album) REFERENCES Albums(Album),
FOREIGN KEY(Genre) REFERENCES Genre(Genre),
FOREIGN KEY(SubGenre) REFERENCES SubGenre(SubGenre));
create table Artists(Artist varchar(40) not null, Genre varchar(10) not null, Band_Group varchar(40),
PRIMARY KEY(Artist),
FOREIGN KEY Genre REFERENCES Genre(Genre));
create table Genre(Genre varchar(10) not null, RelatedGenres varchar(10) not null); PRIMARY KEY(Genre);
FOREIGN KEY RelatedGenres REFERENCES RalatedGenres(Genre);
create table RelatedGenres(Genre varchar(10) not null, RelatedGenre varchar(10));
create table SubGenre(SubGenre varchar(30) not null, Genre varchar(10) not null,
PRIMARY KEY(SubGenre),
FOREIGN KEY(Genre) REFERENCES Genre(Genre));
我如何安排的方式這些表在那裏我沒有爲試圖用一個外鍵如流派多出現錯誤一張桌子。
希望你們中的一些人能幫忙!
您可以包含確切的錯誤輸出嗎? –
你有什麼錯誤? –
我會得到#1005 - 無法創建表'bpmtest'.'genre'(錯誤:150「外鍵約束不正確」 – KagemushaShen