Laravel 4 - Eloquent不绑定参数

时间:2014-03-08 21:56:54

标签: php mysql sql laravel laravel-4

在尝试向数据库表添加新行时,我收到以下错误:

  

SQLSTATE [23000]:完整性约束违规:1452无法添加或   更新子行:外键约束失败   (testastranslations,CONSTRAINT translations_ibfk_2 FOREIGN KEY   (labelId)参考labelid))(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

0 个答案:

没有答案