Support » Fixing WordPress » New posts defaulting to '0' primary key

  • Resolved bdemont

    (@bdemont)



    Hello,

    I have a huge problem in my wordpress database after reinstall a dump file on the same host :

    Every new things are set on 0 primary key, so it doesn’t work :
    This is my php log :

    WordPress database error Duplicate entry '0' for key 'PRIMARY' for query INSERT INTO <code>wp_posts</code> (<code>post_author</code>,<code>post_date</code>,<code>post_date_gmt</code>,
    <code>post_content</code>,<code>post_content_filtered</code>,<code>post_title</code>,<code>post_excerpt</code>,<code>post_status</code>,<code>post_type</code>,
    <code>comment_status</code>,<code>ping_status</code>,<code>post_password</code>,<code>post_name</code>,<code>to_ping</code>,<code>pinged</code>,<code>post_modified</code>,
    <code>post_modified_gmt</code>,<code>post_parent</code>,<code>menu_order</code>,<code>post_mime_type</code>,<code>guid</code>) 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 ##\wp-admin\includes\post.php on line 567

    And i have this problem for every things: medias, shortcode, all new added things.

    I read about that : http://wordpress.stackexchange.com/questions/165277/new-posts-defaulting-to-0-primary-key

    Can i do that on all tables in my database ?
    ALTER TABLE wp_posts AUTO_INCREMENT = 1001;

    Or have you another solution ?

    I read a similar issue : http://gielberkers.com/fix-duplicate-entry-1-key-primary-data-migration-magento/ with only this sql code : SET sql_mode=’NO_AUTO_VALUE_ON_ZERO’;

    I’m on a production server so i wanted to have your opinion about that before testing.

    Thank you,
    Ben

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Ben,

    Yes, it looks like you need to set your database columns primary key to ‘auto-increment’. You may need to do this for each database table.

    You should be able to do this from within PHPMyAdmin; from your hosts cPanel.

    Hi Josh,

    I did this sql code on wp_posts and wp_postmeta :
    ALTER TABLE wp_postmeta AUTO_INCREMENT = 10001;
    ALTER TABLE wp_posts AUTO_INCREMENT = 10001;

    i have the same problem when i upload a media :

    “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)”

    How can i avoid this entry 0 ?

    Thank you !

    This is my wp_posts stucture, nothing change after ALTER TABLE sql query
    http://s1.postimg.org/s10vrfznz/Capture_d_cran_2015_01_05_15_07_51.png

    Hi found the solution !

    The problem was the import in the database of wordfence plugins tables (wfconfig, wflogins, wfhits etc..). So the table of Auto Increment in the end of SQL file was not wrote.

    So i reimport only the part auto increment and it’s working now :


    — AUTO_INCREMENT for exported table

    Have a good day,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘New posts defaulting to '0' primary key’ is closed to new replies.