首页 > 解决方案 > 键“P​​RIMARY”的重复条目“制造商名称-0”

问题描述

我充其量是一个中间人,我们将不胜感激。我正在尝试上传包含药物、制造商、通用名称等数据库的 csv 文件。

我将它用于 .php

$this->db->insert('acc_coa',$manufacturer_coa); }

    $check_category = $this->db->select('*')->from('product_category')->where('category_name',$insert_csv['category_id'])->get()->row();
    if(!empty($check_category)){
        $category_id = $check_category->category_id;
    }else{
            $categorydata=array(
        'category_name'         => $insert_csv['category_id'],
        'status'                => 1
        );
              if ($count > 0) {
    $this->db->insert('product_category',$categorydata);
}

这对于数据库:

CREATE TABLE acc_coa( HeadCodevarchar(50) COLLATE utf8_unicode_ci NOT NULL, HeadNamevarchar(100) COLLATE utf8_unicode_ci NOT NULL AUTO_INCREMENT, PHeadNamevarchar(50) COLLATE utf8_unicode_ci NOT NULL, HeadLevelint(11) NOT NULL, IsActivetinyint(1) NOT NULL, IsTransactiontinyint(1) NOT NULL, customer_idint(11) DEFAULT NULL, manufacturer_idint(11) DEFAULT NULL, IsGLtinyint(1) NOT NULL, HeadTypechar(1) COLLATE utf8_unicode_ci NOT NULL, IsBudgettinyint(1) NOT NULL, IsDepreciationtinyint(1) NOT NULL, DepreciationRatedecimal(18, 2)非空, CreateByvarchar(50)整理utf8_unicode_ci非空, CreateDate日期时间非空, UpdateByvarchar(50)整理utf8_unicode_ci非空, UpdateDate日期时间非空,主键(HeadName) ) 引擎=InnoDB 默认字符集=utf8 COLLATE=utf8_unicode_ci;

但是任何时候我尝试我都会得到这个

错误号:1062

键“P​​RIMARY”的重复条目“制造商名称-0”

插入acc_coa( HeadCode, HeadName, PHeadName, HeadLevel, IsActive, IsTransaction, IsGL, HeadType, IsBudget, manufacturer_id, IsDepreciation, DepreciationRate, CreateBy, CreateDate) 值 ('502020000001', '制造商名称-0', '应付帐款', '3', '1', '1', '0' , 'L', '0', 0, '0', '0', '1', '2021-05-27 18:15:47')

文件名:C:/wamp64/www/efkwa/system/database/DB_driver.php

行号:691

标签: phpmysqldatabasecodeigniter

解决方案


此错误表明您已经输入了具有该值的示例/行(制造商名称-0),主键充当每个示例的唯一标识符,因此不能在表的其他示例/行中重复


推荐阅读