I've started having problems with drupal CVS. When I add a new story, blog or forum page, I get something like the following:

user error: Duplicate entry '3' for key 1
query: INSERT INTO node (title, body, uid, created, type, status, promote, moderate, static, comment, teaser, changed, nid) VALUES ('forum topic', 'this is another forum topic', '1', '1053092880', 'forum', '1', '0', '0', '0', '2', 'this is another forum topic', '1053092898', '3') in /home/sites/site88/web/drupal/includes/database.mysql.inc on line 75.

Drupal appears to be reusing old nid values and not incrementing. This does not seem to be a problem with book pages. I updated mysql manually but the structure of the table looks OK. A similar problem is happening with comments:

user error: Duplicate entry '1' for key 1
query: INSERT INTO comments (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users) VALUES (1, 36, 0, 1, 'comment', 'this is a comment', '81.106.39.36', 1053094317, 0, 0, 'a:1:{i:0;i:0;}') in /home/sites/site88/web/drupal/includes/database.mysql.inc on line 75.

warning: Cannot add header information - headers already sent by (output started at /home/sites/site88/web/drupal/includes/common.inc:35) in /home/sites/site88/web/drupal/includes/common.inc on line 419.

Does anyone have any idea why this might be happening?

Comments

droopy’s picture

Sorry, I've just discovered that the sequences table also needs changing: comments > comments_cid, node > node_nid. That fixed it.

kennysto@drupal.org’s picture

I have a similar problem. I messed up upgrading 4.3 end ended up updating some tables manually. I see in the sequences table there are 4 itmes: users_id, node_id, vocabulary_id and term_data_tid.

I guess I update node_id to my last node entry?

What are the others?, since I have not imported user or vocabulary data these should be ok right? i.e I have created users and vocabulary from fresh after the upgrade.

killes@www.drop.org’s picture

Simply set all values to higher values than you currently have. Missing a few numbers is no problem.

Gidget Digit’s picture

Yes, more documentation is needed for us who are committed to upgrading, but confronted with complicated mysql errors. I've just gone from Drupal 4.3.2 to 4.4 and am quite pleased with my new modules. (I've lost a number of themes, but that's another story.) However, we cannot add stories because of this same duplicate node_nid error, trying to add things into already existing node numbers. (in fact, since the image module is now working, when you create a story, it's able to add the images, but adds them into the wrong node, the old numbers!)

So, I see have the same problem as described above, and from looking at the sequences table, I see the node_nid is set too low. BUT HOW DO I CHANGE IT?? I have gone through all these docs here, and tried to understand the ALTER TABLE docs at mysql.com ... Still I can't figure out what command I need to reset that node number to something higher. (and I'd like to know how many nodes we currently have, so I don't have to guess and keep trying.)

Thanks for any help. I did run the upgrade script, and have followed all the existing 4.4 upgrade documentation to the letter, I believe.

regards,
-=pj=-

Gidget Digit’s picture

Hey. not that anyone seems to be following, BUT just in case someone else has the same troubles when upgrading, I figured out the MySQL commands you need to know to reset your node_nid

mysql> lock tables sequences write;
mysql>select id from sequences where name = "node_nid";
mysql> replace into sequences values ('node_nid', 1067);
       (or instead of 1067, whatever number is next 
       after the existing nodes)
mysql>unlock tables;

And there ya go, it should start adding your new nodes as new, higher, numbers, instead of trying to write over existing nodes.

good luck,
-=pj=-

Herbt’s picture

Thanks for the sql commands, it fixed the problem. I had inserted my entries from a 4.4 instance into a new 4.51.

Thomas Sewell’s picture

For those looking to fix this same problem, here's a "complete" method that includes the vid from the node_revisions table, including determining the new numbers.

UPDATE sequences SET id=(SELECT max(nid) FROM node) WHERE name='node_nid';
UPDATE sequences SET id=(SELECT max(vid) FROM node_revisions) WHERE name='node_revisions_vid';

This is especially useful for running after your module creates a bunch of new node and node_revisions records.

tulula’s picture

I delete the users it said that were duplicates, and it's ongoing where it keeps coming up saying more and more users are duplicates. In the sequences table, are you suggesting that you just set the ID numbers to a really high number so no conflicts? IE, with users, if I quite a number of users, do I need to make sure the ID is higher than the total number of expected users? I'm confused. Want these errors to go AWAY! :)

Lisa

eva’s picture

just had the same problem with my node id - if you go into sequences table, and find users id and just manually change the number to one higher than your highest user id for your site, then it should work (same thing for any other id#). hope that helps.
eva

al’s picture

Maybe we should have an advanced troubleshooting section for people who know what they're doing. This problem keeps cropping up and although it's reasonably obvious what's going on once you start to look at it (and the code) it does leave you wondering what's up for a few minutes.

On the other hand, this problem could also be solved by writing some kind of generic import module, or some skeleton PHP scripts, or even just a README for migrating your data.

karunadev’s picture

When adding any content type an error is generated;

user error: Duplicate entry '49'

The entry value increments by one for each attempt.

Happens for two totally new installs of Civicspace 8.2, on on a windows dev machine and LAMP on Site5. In both cases, when adding a new node. Both cases Cache Support is disabled (default setting).

Several other users are indicating the same:
http://civicspacelabs.org/home/node/15323
http://civicspacelabs.org/home/node/15334

Any suggestions?

Full error message below.

user error: Duplicate entry '49' for key 1
query: INSERT INTO node (status, moderate, promote, sticky, comment, title, body, format, uid, created, type, teaser, changed, nid) VALUES('1', '0', '1', '0', '2', 'bo', 'bo', '1', '2', '1134020060', 'blog', 'bo', '1134020069', '49') in /home/mangrove/public_html/hrih/includes/database.mysql.inc on line 66.

warning: Cannot modify header information - headers already sent by (output started at /home/mangrove/public_html/hrih/includes/common.inc:384) in /home/mangrove/public_html/

Manually incrementing the sequences.node_nid by 300 generates another error:
user error: Table 'civ82.term_access' doesn't exist
query: SELECT * FROM term_access where tid = '0' in C:\dev\code\web\civ82\includes\database.mysql.inc on line 66.
warning: Cannot modify header information - headers already sent by (output started at C:\dev\code\web\civ82\includes\common.inc:384) in C:\dev\code\web\civ82\includes\common.inc on line 192.

It is true that the table term_access does not exist, but it also does not exist in 8.2 rc7 (which did not produce these errors).

Any ideas?

ToddZ-1’s picture

I was also getting Davrgould's error with a brand-new CivicSpace installation. Trying get a blog entry to post:

user error: Duplicate entry '49' for key 1
query: INSERT INTO cms_node (title, body, format, uid, type, teaser, status, moderate, promote, sticky, comment, created, changed, nid) VALUES('[blog title]', '[blog body]', '1', '', '1', '', '2', '1136703610', '1136703610', '49') in /home/[userid]/public_html/includes/database.mysql.inc on line 66.

warning: Cannot modify header information - headers already sent by (output started at /home/[userid]/public_html/includes/common.inc:384) in /home/[userid]/public_html/includes/common.inc on line 192.

I was able to use phpMyAdmin through my host's cPanel to increment the cms_node_nid to 53 (in table cms_sequences.) This has let me post blog entries.

Still, seems like something that shouldn't happen with a fresh install.

executex’s picture

Drupal 6.x doesn't have sequences table anymore... how stupid are drupal developers? Now where do we find node_nid value?

natuk’s picture

Not stupid at all... incrementing ids in tables in D6 are dealt by the db itself. If you want to reset nid, then go to the node table and execute:
ALTER TABLE node AUTO_INCREMENT = 1;
as instructed here:
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html