#1062 - 键 'PRIMARY' 的重复条目 0' [英] #1062 - Duplicate entry 0' for key 'PRIMARY'

查看:55
本文介绍了#1062 - 键 'PRIMARY' 的重复条目 0'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

INSERT INTO `crm_customer` (`customerid`, `firstname`, `lastname`, `address`, 
  `telephoneno`, `companyname`, `fax`, `comments`, `countryid`, `statename`, 
  `cityname`, `emailaddress`, `zipcode`, `dateofbirth`, `unsubscribe`) 
VALUES ('0', 'jhghjgfk', 'kghjkj', 'hjkghjgh', '8776785', 'hjghjkgyjk', 
     '457665', 'jghjgfhj', '0', 'ghjgfjgf', 'gjgfhj', 'ghjgfhjgfj', 
     '764574576', '2017-03-13', '')

我收到的错误是`#1062 - 键'PRIMARY'的重复条目0'

I'm getting error as `#1062 - Duplicate entry 0' for key 'PRIMARY'

推荐答案

如果你有一个自动递增列,你不需要 key primary 的值.假设你的 key primary 是 customerid,你应该使用:

If you have an auto increment column you don't need the value for key primary .. assuming you key primary is customerid you should use:

    INSERT INTO `crm_customer` ( `firstname`, `lastname`, `address`, 
  `telephoneno`, `companyname`, `fax`, `comments`, `countryid`, `statename`, 
  `cityname`, `emailaddress`, `zipcode`, `dateofbirth`, `unsubscribe`) 
VALUES ( 'jhghjgfk', 'kghjkj', 'hjkghjgh', '8776785', 'hjghjkgyjk', 
     '457665', 'jghjgfhj', '0', 'ghjgfjgf', 'gjgfhj', 'ghjgfhjgfj', 
     '764574576', '2017-03-13', '')

简单地避免insert对应部分的列名和值.

Simply avoid the column name and value in the corresponding part of the insert.

或者,您可以在列名列表中使用它,但使用 null 值:

Or, you can use it in column name list but with null value:

    INSERT INTO `crm_customer` (`customerid`,  `firstname`, `lastname`, `address`, 
  `telephoneno`, `companyname`, `fax`, `comments`, `countryid`, `statename`, 
  `cityname`, `emailaddress`, `zipcode`, `dateofbirth`, `unsubscribe`) 
VALUES ( null, 'jhghjgfk', 'kghjkj', 'hjkghjgh', '8776785', 'hjghjkgyjk', 
     '457665', 'jghjgfhj', '0', 'ghjgfjgf', 'gjgfhj', 'ghjgfhjgfj', 
     '764574576', '2017-03-13', '')

而且,如果你没有自动增量添加它:

And, if you don't have auto increment add it:

 ALTER TABLE crm_customer MODIFY COLUMN customerid INT auto_increment

这篇关于#1062 - 键 'PRIMARY' 的重复条目 0'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆