我收到错误
完整性约束违规:1452无法添加或更新子行:外键约束失败(
cv_localv4
。cv_answer_languages
,CONSTRAINTRelationship10
FOREIGN KEY(id_cv_language_levels
)参考cv_languages_levels
(id_cv_language_levels
)ON更新更新行动N)
尝试将值插入cv_answer_languages表时。
应插入的所有值都正确且有效。
我已经阅读了十几个类似的问题,但仍然没有运气:(
我添加了语言表的图片,因此您可以存在值:http://prntscr.com/71vw0d
代码输出:
17 id_cv_languages_levels
13 id_cv
1 id_language
2 id_cv_questions
我无法补充。 //这只是回显消息from try{code below}catch (PDOException $e)
SQLSTATE [23000]:完整性约束违规:1452无法添加或更新子行:外键约束失败(
cv_localv4
。cv_answer_languages
,CONSTRAINTRelationship10
FOREIGN KEY({{ 1}})REFERENCESid_cv_language_levels
(cv_languages_levels
)ON更新更新行动N)
id_cv_language_levels
cv_answer_languages表
$array=array(
"listening"=>filter_input(INPUT_POST, 'listening'), //just values like a1,b2,c2 etc...
"reading"=>filter_input(INPUT_POST, 'reading'),
"spoken_interaction"=>filter_input(INPUT_POST, 'spoken_interaction'),
"spoken_production"=>filter_input(INPUT_POST, 'spoken_production'),
"writing"=>filter_input(INPUT_POST, 'writing'),
);
$language=filter_input(INPUT_POST, 'language'); //1 for English etc..
$sql2=$db->prepare("INSERT INTO `cv_answer_languages`(`id_cv_language_levels`, `id_cv`, `id_language`, `id_cv_questions`) VALUES
(:id_cv_languages_levels,:id_cv,:id_language,:id_cv_questions);");
$sql2->bindParam(':id_cv_languages_levels',$lang_lev_last_id,PDO::PARAM_INT);
$sql2->bindParam(':id_cv',$cv_id_query,PDO::PARAM_INT);
$sql2->bindParam(':id_language',$language,PDO::PARAM_INT);//broken
$sql2->bindParam(':id_cv_questions',$id_cv_question,PDO::PARAM_INT);
$sql2->execute();
cv_languages_levels
CREATE TABLE IF NOT EXISTS `cv_answer_languages` (
`id_cv_language` int(11) NOT NULL,
`id_cv_language_levels` int(11) DEFAULT NULL,
`id_cv` int(11) DEFAULT NULL,
`id_language` int(11) DEFAULT NULL,
`id_cv_questions` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;
语言表
CREATE TABLE IF NOT EXISTS `cv_languages_levels` (
`id_cv_language_levels` int(11) NOT NULL,
`listening` varchar(20) COLLATE utf8_slovenian_ci DEFAULT NULL,
`reading` varchar(20) COLLATE utf8_slovenian_ci DEFAULT NULL,
`spoken_interaction` varchar(20) COLLATE utf8_slovenian_ci DEFAULT NULL,
`spoken_production` varchar(20) COLLATE utf8_slovenian_ci DEFAULT NULL,
`writing` varchar(20) COLLATE utf8_slovenian_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;
cv table
CREATE TABLE IF NOT EXISTS `languages` (
`id_language` int(11) NOT NULL,
`language` varchar(45) COLLATE utf8_slovenian_ci DEFAULT NULL,
`short` varchar(15) COLLATE utf8_slovenian_ci DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=108 DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;