gpt4 book ai didi

mysql - MySQL代码中的错误代码1217

转载 作者:行者123 更新时间:2023-11-29 06:14:27 27 4
gpt4 key购买 nike

<分区>

我的 MySQL 代码中出现错误:Error 1217。我的 MySQL 代码是

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com