HIRE US

Let us help you with your Drupal requirements

To prevent automated spam submissions leave this field empty.

Many Drupal users have encountered a Duplicate entry error when adding a new node to their Drupal sites. The error message is as follows "# 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." If you are encountering the same error in your Drupal site then read on to find out the fix.

This error occurs as a result of a problem during a database upgrade in which auto_increment is not set for the node_revisions table. Here are the steps for getting it fixed.

  • First check if 'vid' is a primary key on node_revisions and also check if it is set to auto_increment.
  • If it is not, then obtain the last nid using the following command
    SELECT max( nid ) FROM `node` 
  • Now add 1 to the result obtained in the above query and replace MAXNID+1 in the following code
    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=MAXNID+1
    ALTER TABLE `node_revisions` AUTO_INCREMENT=MAXNID+1
  • This should fix the issue.
  • If you are running Drupal 6.10 you can use the following code to do the job

    SELECT max( nid ) FROM `node` 
    ALTER TABLE `node` AUTO_INCREMENT=MAXNID+1
    ALTER TABLE `node_revisions` AUTO_INCREMENT=MAXNID+1

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. We can provide a wide range of Drupal services to help you maintain and manage your Drupal websites. Get in touch with us to know more.

Post your comments / questions