While trying to add a new row to a database table, I'm getting the following error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
testas
.translations
, CONSTRAINTtranslations_ibfk_2
FOREIGN KEY (labelId
) REFERENCESlabel
(id
)) (SQL: updatetranslations
setlabelId
= whereid
= 103)
As you can see, it doesn't bind a parameter to labelId
. What's causing this?
EDIT:
$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