我的一个表里有个自增字段(主键),
show create table 显示AUTO_INCREMENT=27
但是新增记录的时候显示:
1062  Duplicate entry '0-0' for key 'PRIMARY'这是怎么回事呢,遇到几次了。其他表的自增字段都正常的。

解决方案 »

  1.   

    | t_register | CREATE TABLE `t_register` (
      `id` bigint(18) NOT NULL AUTO_INCREMENT,
      `plamform` decimal(22,0) NOT NULL,
      `businessid` decimal(22,0) NOT NULL,
      `mobilemodeid` decimal(22,0) NOT NULL,
      `username` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
      `majversion` decimal(22,0) DEFAULT NULL,
      `hypversion` decimal(22,0) DEFAULT NULL,
      `progversion` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
      `dynamic` decimal(22,0) DEFAULT '1',
      `english` decimal(22,0) DEFAULT '0',
      `moveor` decimal(22,0) DEFAULT '0',
      `pricetype` decimal(22,0) NOT NULL,
      `licensetype` decimal(22,0) NOT NULL,
      `expire` bigint(18) DEFAULT NULL,
      `sequencenumber` bigint(18) DEFAULT NULL,
      `cardid` bigint(15) NOT NULL DEFAULT '0',
      `mobile` varchar(16) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
      `regdate` datetime NOT NULL,
      `cpcode` decimal(22,0) NOT NULL,
      `browpic` decimal(22,0) NOT NULL DEFAULT '0',
      `browring` decimal(22,0) NOT NULL DEFAULT '0',
      `downpic` decimal(22,0) NOT NULL DEFAULT '0',
      `downring` decimal(22,0) NOT NULL DEFAULT '0',
      `browmedia` decimal(22,0) NOT NULL DEFAULT '0',
      `downmedia` decimal(22,0) NOT NULL DEFAULT '0',
      `audioplay` decimal(22,0) NOT NULL DEFAULT '0',
      `videoplay` decimal(22,0) NOT NULL DEFAULT '0',
      `ringcombplay` decimal(22,0) NOT NULL DEFAULT '0',
      `audiocombplay` decimal(22,0) NOT NULL DEFAULT '0',
      `browtext` decimal(22,0) NOT NULL DEFAULT '0',
      `channelid` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
      PRIMARY KEY (`id`),
      KEY `xkregdate` (`regdate`),
      KEY `xkregismi` (`cardid`),
      KEY `xkregmobilecode` (`businessid`,`mobilemodeid`)
    ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8 
      

  2.   

    表什么引擎,SQL语句是什么,修理一下此表试试,错误日志中有无内容
      

  3.   

    其他键重复了吧
    KEY `xkregdate` (`regdate`),
      KEY `xkregismi` (`cardid`),
      KEY `xkregmobilecode` (`businessid`,`mobilemodeid`)
    PRIMARY KEY (`id`),
      

  4.   

    mysql> INSERT INTO `t_register` VALUES (null, '1', '1', '443', null, '1', '5', 'V1.0.1358', '1', '0', '0', '0', '1', '4294967295', '256', '1234567890', '', '2012-12-28 11:16:25', '1', '866', '0', '90', '0', '0', '0', '0', '0', '0', '0', '711', null);
    1062 - Duplicate entry '0-0' for key 'PRIMARY'
      

  5.   

    改成  MyISAM  修复后照旧
      

  6.   

    OPTIMIZE TABLE `t_register`
    再插入试试
      

  7.   

    新建立1张表,将数据导入,在MYSQL命令行下运行
    create table newtt like `t_register`;
    insert into newtt select * from `t_register`
      

  8.   

    找到问题原因了,原来是触发器里将New.id插入另外一张表,这个触发器是before,导致new.id是0,从oracle转过来的,oracle 和 mysql的差别咯谢谢大家!
      

  9.   

    呵呵,解决就好,没想到还有TRIGGER,提问也有技巧的