Database Error Occurred Error Number: 1062

前端 未结 1 614
感情败类
感情败类 2021-01-26 05:53

i tried to make option update three table with one execution for my CI with sql there, but why its still error?

this is the error warning:



        
相关标签:
1条回答
  • 2021-01-26 06:21

    Your UPDATE clause is setting the id_publisher column to NULL, and, based on the name of the column and the error you're receiving, that column is the table's PRIMARY KEY with a setting of unsigned NOT NULL.

    Because of this, when you do id_publisher = NULL, MySQL converts it to id_publisher = 0 due to the unsigned part. This will execute fine the first time, however, when you run it on a second row you will now be attempting to insert a second primary-key value of 0, which is not allowed.

    Based on the location of the die() statement in your sample code, I'm assuming the following block is the culprit:

       $data1 = array(
        'id_publisher' => $id_publis,
        'publisher' => $publis,
        'artis' => $ar,
        'id_label' => $id_lab);
    
        $this->db->where('id_publisher', $this->input->post('id'), $data);
        $this->db->update("t_publisher",$data1);
    

    Here, your $id_publis variable is either empty or null.

    I would suggest to either remove the id_publisher = NULL portion from the UPDATE clause which is as simple as removing 'id_publisher' => $id_publis, from the $data1 array, or rethink the reason you actually need to set it to null to begin with (in this case, would deleting the row be more beneficial?)

    0 讨论(0)
提交回复
热议问题