public function save(){
if(IS_POST){
$post = I('post.');
if(!isset($post['pkid']) || empty($post['pkid'])){
$result = $this->CourseModel->addInfo($post);
}else{
$result = $this->CourseModel->updateInfo($post);
}
if ($result!==false) {
$this->redirect("Course/index",'',1, '保存成功');
} else {
$this->redirect("Course/index",'',1, '保存失败');
}
}
}
public function updateInfo($data=array()){
if(empty($data)){
return false;
}
$data['modify_time'] = dateTime();
return $this->data($data)->save();
}
ERR: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`elearning`.`course`, CONSTRAINT `course_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `category` (`pkid`) ON DELETE CASCADE ON UPDATE CASCADE)


回复讨论(解决方案)

被修改的表存在外键约束,你修改了不存在的外键约束的记录

被修改的表存在外键约束,你修改了不存在的外键约束的记录


怎么解决那?

你要么取消外键,要么在修改前先确认键存在

09-15 17:30