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

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条)

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染