Mysql duplicate entry error in database.mysql.inc ?

xand - December 20, 2004 - 11:00

I'm getting a rather strange error:

Fatal error: Duplicate entry '0' for key 1 query: INSERT INTO sessions (uid, sid, hostname, timestamp) values(0, '21b04e5c79238c006236422bbcc9fef0', '131.111.128.49', 1103540234) in /home/xand/public_html/includes/database.mysql.inc on line 125

See http://www.symplification.com

Has anyone got any idea why this might be happening?

I haven't changed anything at all since the last time I was able to access the site (approx 12 hours ago...)

I solved the problem by

xand - December 20, 2004 - 11:24

I solved the problem by dropping the table and recreating it: but has anyone got any idea why this might have happened? or is it eimply database corruption?

Similar problem?

leafish_paul - December 20, 2004 - 19:23

I'm tackling a similar problem myself. I have written a custom module which stores additional details for a new node type in a separate table named bxms_slides. When creating a new node of this type, a row is inserted into the node table with, say nid=149. Then in the _insert hook within my module I insert the rest of the data into the second table using

INSERT INTO bxms_slides(nid, ... ) VALUES ($node->nid, ... )

$node->nid is set correctly, but when it inserts the row the value of nid inserted is the next 'auto incremented' value for the table, and not (eg) 149. I have removed the auto_increment field from my own table, flushed the cache and removed orphaned/mismatched entries in both tables, but I'm still getting the same problem.

I'll post any info if I manage to fix the bugger.

---
paul byrne
web monkey - http://www.leafish.co.uk/

Grr.

leafish_paul - December 20, 2004 - 19:40

Grr. It seems this is a problem with my database, as manually inserting a new row:

INSERT INTO bxms_slides(nid,content) VALUES (149,'test');

still inserts a row with nid=127... it must be a problem with the table's indexing?

edit Me = spazz. I should have noticed that it was always inserting the value 127... I had the field set as TINYINT instead of INT. Fixed now... cheers!

---
paul byrne
web monkey - http://www.leafish.co.uk/

Same problem

pholm - March 23, 2006 - 19:08

I have the same problem, and I haven't been able to fix it by deleting everything from my sessions table.

The error started after I added a new user and switched a few times between admin and attempting to login as the new user, and changed his password several times. I'm not sure which action broke the database but I can't seem to fix it now.

Any suggestions would be appreciated. I can't afford to delete the entire database as it has information in it I need.

Solution

Harry Slaughter - March 24, 2006 - 17:21

This problem occurs when you delete "user 0" in your users table. Drupal needs this user entry when dealing with anonymous users.

Run the following SQL in your drupal database:

insert into `users` ( `uid`) values ( '0' );

That should fix it.

--
http://devbee.com/

Addition to the solution

moondancerjen - June 16, 2008 - 20:10

You also need to give the anonymous user the anonymous role.

INSERT INTO `users_roles` (`uid`, `rid`) VALUES ('0', '1');

Hope this helps anyone else who comes across this page looking for a solution.

 
 

Drupal is a registered trademark of Dries Buytaert.