Home > Backend Development > PHP Tutorial > 执行update更新时,出错,求大神指点

执行update更新时,出错,求大神指点

WBOY
Release: 2016-06-20 12:36:59
Original
1276 people have browsed it

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)


回复讨论(解决方案)

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

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


怎么解决那?

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template