在尝试向数据库表添加新行时,我收到以下错误:
SQLSTATE [23000]:完整性约束违规:1452无法添加或 更新子行:外键约束失败 (
testas
。translations
,CONSTRAINTtranslations_ibfk_2
FOREIGN KEY (labelId
)参考label
(id
))(SQL:更新translations
集labelId
=其中id
= 103)
如您所见,它不会将参数绑定到labelId
。造成这种情况的原因是什么?
编辑:
$labelKey = Label::max('key') + 1;
$label = new Label(array('key' => $labelKey));
$label->save(); //the label gets saved in the labels table
$title = new Translation(array('phrase' => $input['title']));
$title->language()->associate($language);
$title->label()->associate($label);
$title->save(); //this part is failing