When trying to create a new blog post, WordPress is showing a Database error:

 WordPress database error Duplicate entry '0' for key 'PRIMARY' for query INSERT INTO `wp_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 (5,'2014-10-13 11:19:21','0000-00-00 00:00:00','','','Auto Draft','','auto-draft','post','open','open','','','','','2014-10-13 11:19:21','0000-00-00 00:00:00',0,0,'','') made by get_default_post_to_edit, wp_insert_post PHP Warning: Creating default object from empty value in C:\..\..\..\httpdocs\wp-admin\includes\post.php on line 567

I am able to edit past posts but the issue appears when trying to create a new post.

Any suggestions on a work around or fix to stop new posts from defaulting to the 0 as the Primary Key?

WordPress V4.0
PHP 5.4

2 Answers
2

This is only my best guess. I can’t see a definitive answer with the information provided.


The primary key for wp_posts should be set to ID. The primary key is giving the error. Since ID is not defined in the query, it is likely that the AUTO_INCREMENT value has been set to 0, or is no longer incrementing.

I would look into your database and find the AUTO_INCREMENT value. I bet it’s set to 0 for some reason.

Take a backup of your database before making any changes to the database.

If the AUTO_INCREMENT value is set to 0, you want to set it to a value that hasn’t yet been reached. Go to wp_posts and find the highest value ID and set it to one more than that (or a few more than that, just to be safe).

For example, if the highest value ID in wp_posts is 1000:

ALTER TABLE wp_posts AUTO_INCREMENT = 1001;

If this is not the issue, ensure that the PRIMARY_KEY for the table is set to ID.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *