douyangcheng4965 2014-02-18 09:17
浏览 72

密钥1的重复条目1 - 没有重复

Hi i'm trying to import a database to alive server and I keep getting this error message:

SQL query:

--
-- Dumping data for table `wp_2_comments`
--
INSERT INTO  `wp_2_comments` (  `comment_ID` ,  `comment_post_ID` ,  `comment_author` ,  `comment_author_email` , `comment_author_url` ,  `comment_author_IP` ,  `comment_date` ,  `comment_date_gmt` ,  `comment_content` ,  `comment_karma` , `comment_approved` ,  `comment_agent` ,  `comment_type` ,  `comment_parent` ,  `user_id` ) 
VALUES ( 1, 1,  'Mr WordPress',  '',  'http://www.kbee.co.za/',  '',  '2013-12-22 17:34:17',  '2013-12-22 17:34:17', 'Hi, this is a comment.
To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.', 0,  '1',  '',  '', 0, 0 ) ;

MySQL said: Documentation

1062 - Duplicate entry '1' for key 1

Below is the structure of that particular table:

--
-- Table structure for table `wp_2_comments`
--

CREATE TABLE IF NOT EXISTS `wp_2_comments` (
  `comment_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `comment_post_ID` bigint(20) unsigned NOT NULL DEFAULT '0',
  `comment_author` tinytext NOT NULL,
  `comment_author_email` varchar(100) NOT NULL DEFAULT '',
  `comment_author_url` varchar(200) NOT NULL DEFAULT '',
  `comment_author_IP` varchar(100) NOT NULL DEFAULT '',
  `comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `comment_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `comment_content` text NOT NULL,
  `comment_karma` int(11) NOT NULL DEFAULT '0',
  `comment_approved` varchar(20) NOT NULL DEFAULT '1',
  `comment_agent` varchar(255) NOT NULL DEFAULT '',
  `comment_type` varchar(20) NOT NULL DEFAULT '',
  `comment_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
  `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`comment_ID`),
  KEY `comment_post_ID` (`comment_post_ID`),
  KEY `comment_approved_date_gmt` (`comment_approved`,`comment_date_gmt`),
  KEY `comment_date_gmt` (`comment_date_gmt`),
  KEY `comment_parent` (`comment_parent`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `wp_2_comments`
--

INSERT INTO `wp_2_comments` (`comment_ID`, `comment_post_ID`, `comment_author`, `comment_author_email`, `comment_author_url`, `comment_author_IP`, `comment_date`, `comment_date_gmt`, `comment_content`, `comment_karma`, `comment_approved`, `comment_agent`, `comment_type`, `comment_parent`, `user_id`) VALUES
(1, 1, 'Mr WordPress', '', 'http://www.kbee.co.za', '', '2013-12-22 17:34:17', '2013-12-22 17:34:17', 'Hi, this is a comment.
To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.', 0, '1', '', '', 0, 0);

From what I have seen in other topics this could be because a table is being duplicated or or the primary key field is not auto incrementing. The structure in the table has the primary key field set to auto increment and I already tried dropping that particular table and trying to import again but I am finding no joy.

  • 写回答

1条回答 默认 最新

  • douchengfei3985 2014-02-18 09:24
    关注

    For auto increment values even if you delete the row with value 1, the next value of auto increment col will be 2 and not 1.so truncate the table using

    truncate wp_2_comments

    and then try to insert the value which will start the count from 1.

    also change this

     ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
    

    to

     ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    

    First execute this query

    CREATE TABLE IF NOT EXISTS `wp_2_comments` (
      `comment_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `comment_post_ID` bigint(20) unsigned NOT NULL DEFAULT '0',
      `comment_author` tinytext NOT NULL,
      `comment_author_email` varchar(100) NOT NULL DEFAULT '',
      `comment_author_url` varchar(200) NOT NULL DEFAULT '',
      `comment_author_IP` varchar(100) NOT NULL DEFAULT '',
      `comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
      `comment_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
      `comment_content` text NOT NULL,
      `comment_karma` int(11) NOT NULL DEFAULT '0',
      `comment_approved` varchar(20) NOT NULL DEFAULT '1',
      `comment_agent` varchar(255) NOT NULL DEFAULT '',
      `comment_type` varchar(20) NOT NULL DEFAULT '',
      `comment_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
      `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
      PRIMARY KEY (`comment_ID`),
      KEY `comment_post_ID` (`comment_post_ID`),
      KEY `comment_approved_date_gmt` (`comment_approved`,`comment_date_gmt`),
      KEY `comment_date_gmt` (`comment_date_gmt`),
      KEY `comment_parent` (`comment_parent`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
    

    then execute this query

    truncate wp_2_comments
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试