我收到錯誤:Error 1217
在我的MySQL
代碼中。我MySQL
代碼是MySQL代碼中的錯誤代碼1217
DROP TABLE IF EXISTS Formed;
DROP TABLE IF EXISTS Album;
DROP TABLE IF EXISTS Band;
DROP TABLE IF EXISTS Customers;
DROP TABLE IF EXISTS Track;
CREATE TABLE Formed(
FormedID int AUTO_INCREMENT,
YearFormed int,
CountryFormed varchar(50),
CityFormed varchar(50),
BandMembers varchar(400),
PRIMARY KEY(FormedID))
ENGINE=InnoDB;
CREATE TABLE Track (
TrackID int AUTO_INCREMENT,
AlbumID int AUTO_INCREMENT,
Songs varchar (100),
TrackNumber varchar (20),
Title varchar (30),
TrackDuration varchar (4),
PRIMARY KEY (TrackID))
ENGINE=InnoDB;
CREATE TABLE Album(
AlbumID int AUTO_INCREMENT,
TrackID int AUTO_INCREMENT,
BandID int AUTO_INCREMENT,
KEY(TrackID),
KEY(BandID),
Price varchar(5),
PublicationDate varchar(11),
Title varchar(30),
Genre varchar (36),
PRIMARY KEY(AlbumID))
ENGINE=InnoDB;
CREATE TABLE Band(
BandID int AUTO_INCREMENT,
AlbumID int AUTO_INCREMENT,
KEY(AlbumID),
RecordLabel varchar(50),
PRIMARY KEY(BandID))
ENGINE=InnoDB;
CREATE TABLE Customers (
CustomerID int AUTO_INCREMENT,
CName varchar (20),
CPhone int (11),
CEmail varchar (50),
CPPaid varchar (50),
CPDate date,
PRIMARY KEY (CustomerID))
ENGINE=InnoDB;
ALTER TABLE Track
ADD FOREIGN KEY (AlbumID) REFERENCES Album(AlbumID)ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE Album
ADD FOREIGN KEY (TrackID) REFERENCES Track(TrackID)ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE Album
ADD FOREIGN KEY (BandID) REFERENCES Band(BandID)ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE Band
ADD FOREIGN KEY (AlbumID) REFERENCES Album(AlbumID)ON DELETE SET NULL ON UPDATE CASCADE;
而我得到的錯誤DROP TABLE IF EXISTS Album
Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails
,也恰好爲其他DROP TABLE IF EXISTS
線。我是新手,在MySQL
腳本中使用Foreign Keys
,我不知道爲什麼我會收到這些錯誤。如果任何人都可以幫助我解決這個問題,將不勝感激。我已經嘗試了所有可以通過以下鏈接Bogus foreign key constraint fail
您可能必須以不同的順序砸他們避免違反外鍵約束,首先刪除外鍵,甚至禁用外鍵。 – tadman
@tadman我剛剛將它們從代碼中註釋掉了,它仍然在發生 – smitthy
@Siguza這不是重複的,因爲我已經嘗試了所有給出的答案,它仍然不起作用 – smitthy