我只有这样的50k + SQL查询:
INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES
(357, 1, '2016-06-03 16:35:24', '2016-06-03 16:35:24', 'SOME CONTENT HERE', 'Artykuły', '', 'trash', 'closed', 'closed', '', 'artykuly__trashed', '', '', '2016-06-03 20:52:06', '2016-06-03 20:52:06', '', 0, '038;p=357', 0, 'autoblog_artykuly', '', 0);
(...)
INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES
(357, 1, '2016-06-03 16:35:24', '2016-06-03 16:35:24', 'SOME CONTENT HERE', 'Artykuły', '', 'trash', 'closed', 'closed', '', 'artykuly__trashed', '', '', '2016-06-03 20:52:06', '2016-06-03 20:52:06', '', 0, '38;p=357', 0, 'autoblog_artykuly', '', 0);
所有查询都具有相同的ID,当我尝试通过phpmyadmin将其添加到数据库时,我会收到以下信息:
#1062 - Duplicate entry '357' for key 'PRIMARY'
使用什么更改ID:357来设置自动值?自动递增?
答案 0 :(得分:1)
您应该将ID设置为UNIQUE和AUTO-INCREMENT,并将其从INSERT语句中删除。您永远不必担心ID,它应该由MySQL本身处理。
INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES
(1, '2016-06-03 16:35:24', '2016-06-03 16:35:24', 'SOME CONTENT HERE', 'Artykuły', '', 'trash', 'closed', 'closed', '', 'artykuly__trashed', '', '', '2016-06-03 20:52:06', '2016-06-03 20:52:06', '', 0, '038;p=357', 0, 'autoblog_artykuly', '', 0);
答案 1 :(得分:-1)
您的错误显示您在表设计时设置主键,以便发生此错误。如果要设置自动增量,则只需在列上设置UNIQUE INDEX。