duanjian4698 2014-03-08 21:56
浏览 49

Laravel 4 - Eloquent不绑定参数

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, CONSTRAINT translations_ibfk_2 FOREIGN KEY (labelId) REFERENCES label (id)) (SQL: update translations set labelId = where id = 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
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 win c++ socket
    • ¥15 CanMv K210开发板实现功能
    • ¥15 C# datagridview 栏位进度
    • ¥15 vue3页面el-table页面数据过多
    • ¥100 vue3中融入gRPC-web
    • ¥15 kali环境运行volatility分析android内存文件,缺profile
    • ¥15 写uniapp时遇到的问题
    • ¥15 vs 2008 安装遇到问题
    • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
    • ¥15 找一个网络防御专家,外包的