Home > Enterprise >  Duplicate entry for key 'PRIMARY' codeigniter
Duplicate entry for key 'PRIMARY' codeigniter

Time:07-22

i got error Duplicate entry '19-0' for key 'PRIMARY' after insert all multiple to database

$resp = curl_exec($curl);
$gorong = json_decode($resp);
foreach ($gorong->data as $g){
                        $this->db->insert('mod_auto_harga', array(
                        'sv_id' => '19',
                        'kode' => $g->buyer_sku_code,
                        'keterangan' => $g->product_name,
                        'harga' => $g->price,
                        'status' => $g->seller_product_status,
                        'type' => $g->type,
                        ));
     
        $id = $this->db->insert_id();
 

enter image description here

CodePudding user response:

You set column sv_id as primary key on database. but hardcoded it on insert as 19. remove that column, it should be auto generated on insert.

If you do need all those to have 19 as value. Then from database remove that indexing from that column. and add a new column for primary key.

CodePudding user response:

sv_id must be different. if the autoincrement field can be removed from the insert

  • Related