DEV Community

Zaw Htut Win
Zaw Htut Win

Posted on

MySQL 1062 - Duplicate entry 'xxx' for key 'PRIMARY' Cannot Create New Post in Wordpress

What happened was that the admin could not create the new posts. It show the white page with warnings. At first I was searching through internet relating to that warning, then I came to realize that they are just the warning and not the actual error. The thing was the site I was handling doesn't allow to use FTP. So literally I could not change the wp-config.php to enable debug mode. So I installed the plugin called "Debug" and set the debug mode then viola! the actuall error came out with text in black.

MySQL 1062 - Duplicate entry '400' for key 'PRIMARY'`
Enter fullscreen mode Exit fullscreen mode

So I installed plugin called "SQL Executioner"
and execute the command

describe wp_posts;
Enter fullscreen mode Exit fullscreen mode

Then I got the schema of the wp_posts table. It's ID already set to autoincrement. But how did that ID=400 was inserted,I did'nt know. So I backup the database with "Updraft Plus" plugin and executed the following command to remove that ID = 400 post from wp_posts table

delete from wp_post where ID = 400;
Enter fullscreen mode Exit fullscreen mode

Banzai!
The site was back to normal, no more error when creating new posts. So as a house cleaning I deleted back all the plugins I used for debugging and troubleshooting. Of course I don't want someone to type gibberish in "SQL Executioner" and corrupt the database. So housekeeping was necessary.

Fin

Oldest comments (0)