我收到一條錯誤消息,提示「無法刪除或更新父行,外鍵約束失敗。」當我試圖更新團隊表中的值時。我究竟做錯了什麼?無法刪除或更新父行,外鍵約束失敗
$createTeam ="CREATE TABLE Team(
teamName VARCHAR(30) not null,
division VARCHAR(30) not null,
photo VARCHAR(30),
primary key(teamName, division)
)
engine=innodb";
$createParticipant ="CREATE TABLE Participant(
participantName VARCHAR(30) not null,
techniqueResult DOUBLE(10,2),
trickResult INT(10),
teamName VARCHAR(30) not null,
division VARCHAR(30) not null,
primary key (participantName),
foreign key (teamName, division) references Team(teamName, division)
ON DELETE CASCADE
)
engine=innodb";
$updateTeam = "UPDATE Team SET teamName = '$newTeamName' , division = '$newDivision' WHERE teamName = '$oldTeamName' AND division ='$oldDivision'";
您正在更改Team表中的主鍵值(即teamName,division),而Participant表中的記錄具有該值作爲外鍵。 – PaulF