Heim  >  Artikel  >  Backend-Entwicklung  >  执行update更新时,出错,求大神指点

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

WBOY
WBOYOriginal
2016-06-20 12:36:591238Durchsuche

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)


回复讨论(解决方案)

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

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


怎么解决那?

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn