完整性约束违规 - yii \ db \ IntegrityException

时间:2016-03-10 12:07:45

标签: php yii

在Yii框架中,我面临着删除记录的问题,信息表包含一个与其他表链接的foriegn密钥。我通过删除最后一个信息表中的记录来顺序删除记录。请帮我解决这个问题。

$model = StuMaster::findOne($id);
$address = StuAddress::findOne($model->stu_master_stu_address_id);
$info = StuInfo::findOne($model->stu_master_stu_info_id);
$pastacademics = StuPastacademics::findOne(['pastacad_studenid' => $info->stu_unique_id]);
$guardians = StuGuardians::findAll(['guardia_stu_master_id' => $model->stu_master_id]); 

$pastacademics->delete();
$model->delete();
$info->delete();

完整性约束违规 - yii \ db \ IntegrityException

SQLSTATE [23000]:完整性约束违规:1451无法删除或更新父行:外键约束失败(whizzee_dihedblatstu_info,CONSTRAINT stu_info_ibfk_3 FOREIGN KEY({{ 1}})参考stu_info_stu_master_idstu_master)) 正在执行的SQL是:DELETE FROM stu_master_id WHERE stu_master = 61

0 个答案:

没有答案