Nilesh Bhanse
Nilesh Bhanse

Reputation: 21

Fixing WordPress database error Duplicate entry '0' for key 'PRIMARY' for query INSERT INTO

On Wordpress 4.9.5, I am getting this error on the admin panel when I enable the Simple Error Log plugin.

Here is the error that we get:

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 (14, '2018-04-17 18:24:27', '0000-00-00 00:00:00', '', '', 'Auto Draft', '', 'auto-draft', 'post', 'open', 'open', '', '', '', '', '2018-04-17 18:24:27', '0000-00-00 00:00:00', 0, 0, '', '') made by wp_dashboard, do_meta_boxes, call_user_func, wp_dashboard_quick_press, get_default_post_to_edit, wp_insert_post

I have tried repair this table from PHPMYADMIN, also tried this https://blog.sqlauthority.com/2016/09/12/mysql-fix-error-wordpress-database-error-duplicate-entry-key-primary-query-insert-wp_options/ and https://wordpress.stackexchange.com/questions/165277/new-posts-defaulting-to-0-primary-key but it doesn't resolve.

Pls advise what could be wrong and how to fix that.

Upvotes: 2

Views: 10344

Answers (2)

pepe
pepe

Reputation: 1

... maybe you have to change the id of an existent entry before changing the column settings. If so, you will get an alert "will cause double entry". Look after an ID = 0 and change it to the highest ID value + 1.

Upvotes: 0

Asela Bandara
Asela Bandara

Reputation: 23

I also had the same issue and the following error message was displaying on top of one of my websites:

WordPress database error: [Duplicate entry '0' for key 'PRIMARY'] INSERT INTO Umr_actionscheduler_actions (hook, status, scheduled_date_gmt, scheduled_date_local, schedule, group_id, args) VALUES ('wpforms_email_summaries_fetch_info_blocks', 'pending', '2023-07-02 18:51:31', '2023-07-02 18:51:31', 'O:32:"ActionScheduler_IntervalSchedule":5:{s:22:"\0*\0scheduled_timestamp";i:1688323891;s:18:"\0*\0first_timestamp";i:1688323891;s:13:"\0*\0recurrence";i:604800;s:49:"\0ActionScheduler_IntervalSchedule\0start_timestamp";i:1688323891;s:53:"\0ActionScheduler_IntervalSchedule\0interval_in_seconds";i:604800;}', '2', '{"tasks_meta_id":null}') Skip to main content

This article helped me to solve the issue - https://www.newzealandgoonline.co.nz/how-to-fix-wordpress-database-error-duplicate-entry-0-for-key-primary-for-query-insert-into-wp_usermeta/

In short - set auto-increment to the Primary key of the table.

According to the error message I opened the table "Umr_actionscheduler_actions" in phpMyAdmin. After that clicked on Structure and then clicked on Change next to the primary key - in my case "action_id"

Pressed the check mark under AI and clicked on Save. It worked!

Upvotes: 2

Related Questions