WordPress 4.9.5启用Simple Error Log插件触发主键重复数据库错误
Hey there, let's tackle this database error you're seeing after enabling the Simple Error Log plugin on WordPress 4.9.5. I've run into similar issues with older WP versions and plugins that mishandle custom post type entries, so here's a step-by-step breakdown of how to fix it:
What's Causing This?
The error WordPress database error Duplicate entry '0' for key 'PRIMARY' means the plugin is trying to insert a row into the wp_posts table with an ID value of 0—but the ID column is the primary key, which is supposed to be auto-incrementing and unique. WordPress expects the database to generate a new unique ID automatically for new posts (including plugin-generated log entries), so the plugin is incorrectly forcing an ID of 0 here.
Step 1: Verify the Plugin is the Culprit
First, let's confirm the error stops when the plugin is disabled:
- Access your site via FTP or cPanel File Manager.
- Navigate to
wp-content/plugins/. - Rename the
simple-error-logfolder to something likesimple-error-log-disabled. - Refresh your WordPress admin panel—if the error disappears, you've confirmed the plugin is the source.
Step 2: Fix the wp_posts Table Structure
It's possible your wp_posts table's primary key isn't set to auto-increment properly. Here's how to fix that:
- Log into your hosting control panel and open phpMyAdmin.
- Select your WordPress database from the left sidebar.
- Find the
wp_poststable (replacewp_with your database prefix if you changed it). - Click the "Structure" tab.
- Look for the
IDcolumn: it should be set toINT(11) UNSIGNED NOT NULL AUTO_INCREMENTand marked as the primary key. - If not, click the "Change" link next to the
IDcolumn, check the "AUTO_INCREMENT" box, and save the changes.
Step 3: Remove the Duplicate ID Entry (If Exists)
If there's already a row in wp_posts with ID = 0, we need to delete it first:
- In phpMyAdmin, select your database and click the "SQL" tab.
- Run this query (replace
wp_with your prefix):DELETE FROM wp_posts WHERE ID = 0; - Click "Go" to execute the query.
Step 4: Update or Replace the Plugin
Since WordPress 4.9.5 is an older version, the Simple Error Log plugin might not be compatible with it:
- If the plugin is still maintained, check for an updated version that supports WP 4.9.5 and install it.
- If it's no longer maintained, switch to an alternative error logging plugin (like Error Log Monitor) that's compatible with your WP version.
Important Notes
- Always back up your database before making any changes—this way you can restore it if something goes wrong.
- If you're not comfortable working with phpMyAdmin or database queries, reach out to a developer or your hosting support for help.
内容的提问来源于stack exchange,提问作者Nilesh Bhanse

