duanguan3863 2015-07-31 02:30
浏览 258
已采纳

SQLSTATE [23000]:完整性约束违规:1062重复条目

I have a problem regarding my update, if i have 1 row of data my update works but if I have 2 rows data, I got this problem.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 2 Primary

myController.php

public function update(Partner $partner) {
    $partner->update(array_except(Input::all(), '_token'));
}

Any idea whats the problem?

  • 写回答

3条回答 默认 最新

  • dongtaigan1594 2015-08-07 05:12
    关注

    I changed the query to this

    public function UpdateItems(Item $updateitem, $item_id){ $sname = Input::get('subcategory'); $subname = ItemSubcategory::where('name',$sname)->first(); $input = Input::except('_token'); $updateitem->where('item_id', $item_id) ->update($input, ['subcategory' => $subname->id]); }

    and now my code is working but i have a little problem. All columns can be updated except for the subcategory column. Now my question is that is it possible to update the subcategory column together with the other columns using

    update($input, ['subcategory' => $subname->id])
    

    or is there any way to update the subcategory?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?