Duplicate entry error during node add

Last modified: May 28, 2009 - 02:49

Occurred running Drupal 6.4 using a database migrated from Drupal 5

The error:

# user warning: Duplicate entry '0' for key 2 query: INSERT INTO node (vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) VALUES (0, 'page', 'es', 'eee', 1, 1, 1222437644, 1222437644, 2, 1, 0, 0, 0, 0) in /var/www/webapps/drupal6/includes/common.inc on line 3318.
# user warning: Duplicate entry '0' for key 1 query: INSERT INTO node_comment_statistics (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) VALUES (0, 1222437644, NULL, 1, 0) in /var/www/webapps/drupal6/modules/comment/comment.module on line 607.

Apparently is produced by a problem during database upgrade, because auto_increment is not set for node_revisions table.

Check if 'vid' is PRIMARY KEY on 'node_revisions' and also check that is set to 'auto_increment'

If not try this to fix it:

Obtain last node ID

SELECT max( nid ) FROM `node`

And sum 1 to the number obtained from previous query and replace YOUR_NUMBER with it and run:

ALTER TABLE `node_revisions` ADD PRIMARY KEY ( `vid` )
ALTER TABLE `node_revisions` CHANGE `vid` `vid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT
ALTER TABLE `node` AUTO_INCREMENT=YOUR_NUMBER
ALTER TABLE `node_revisions` AUTO_INCREMENT=YOUR_NUMBER

This Works

I have also had this issue running 6.10 (never upgraded from drupal 5), and can confirm running

SELECT max( nid ) FROM `node`
ALTER TABLE `node` AUTO_INCREMENT=YOUR_NUMBER
ALTER TABLE `node_revisions` AUTO_INCREMENT=YOUR_NUMBER

fixed the issue.

 
 

Drupal is a registered trademark of Dries Buytaert.