同じ問題に関するいくつかの質問を読みましたが、解決策が見つかりませんでした
データベースの構造
CREATE TABLE material (
cve_mat varchar(12),
type_mat varchar(20),
author_mat varchar(40),
status varchar(2),
primary key(cve_mat)
) ENGINE = INNODB;
CREATE TABLE users (
cve_user varchar(8),
name_user varchar(25),
lastn_user varchar(25),
email_user varchar(25),
primary key(cve_user)
)ENGINE = INNODB;
CREATE TABLE material_user (
cve_mat varchar(8),
cve_user varchar(8),
start_mat date,
end_mat date,
foreign key(cve_mat) references material(cve_mat)
ON UPDATE CASCADE
ON DELETE CASCADE,
foreign key(cve_user) references users(cve_user)
ON UPDATE CASCADE
ON DELETE CASCADE
) ENGINE = INNODB;
そして、これらの命令を実行すると:
......
$query = "INSERT INTO material_user VALUES ('$cvemat','$ncontrol',NOW(),DATE_ADD(current_date, interval '$days' day))";
$result = mysql_query($query) or die(mysql_error());
if ($result) {
$query = "UPDATE material SET status = 'YES' WHERE material.cve_mat = '$cvemat'";
$result = mysql_query($query) or die(mysql_error());
if ($result){
return true;
} else {
return false;
}
} else {
return false;
}
そして、このエラーを表示します:
Cannot add or update a child row: a foreign key constraint fails (`biblioteca/material_prestamo`, CONSTRAINT `material_prestamo_ibfk_1` FOREIGN KEY (`cve_mat`) REFERENCES `material` (`cve_mat`) ON DELETE CASCADE ON UPDATE CASCADE)
私はあなたの助けに感謝します!