WordPress数据库错误 Duplicate entry 0 for key PRIMARY

建站 码拜 4年前 (2019-10-17) 1930次浏览 0个评论

为了方便开发网站,在本地电脑部署了一个和线上相同的LNMP环境。安装WordPress ,然后导入线上数据。但是登录后台后,文章编辑、页面编辑功能均无法使用。由于后台并不提示错误原因,需要到服务器上设置wp-config.php 文件,改为

define(‘WP_DEBUG’, true);

刷新后台页面,错误出现了:

WordPress数据库错误: [Duplicate entry ‘0’ for key ‘PRIMARY’]
INSERT INTO `codebye_com_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_content_filtered`, `post_title`, `post_excerpt`, `post_status`, `post_type`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_parent`, `menu_order`, `post_mime_type`, `guid`) VALUES (2, ‘2019-10-18 00:02:28’, ‘0000-00-00 00:00:00’, ”, ”, ‘自动草稿’, ”, ‘auto-draft’, ‘post’, ‘open’, ‘open’, ”, ”, ”, ”, ‘2019-10-18 00:02:28’, ‘0000-00-00 00:00:00’, 0, 0, ”, ”)

解决方法:

使用PhpMyAdmin管理mysql 数据库。找到问题表codebye_com_posts,设置主键Id自增。

执行SQL为:ALTER TABLE `codebye_com_posts` CHANGE `ID` `ID` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;

或者在页面进行设置WordPress数据库错误 Duplicate entry 0 for key PRIMARY

经过以上数据库设置后,刷新网站后台,功能恢复正常。关闭wp-config.php的调试配置define(‘WP_DEBUG’, false); 处理完成。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明WordPress数据库错误 Duplicate entry 0 for key PRIMARY
喜欢 (1)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!