Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Fatal error: Duplicate entry '0' for key 1 query: INSERT INTO sessions (uid, sid, hostname, timestamp) values(0, 'sessionIDisdeleted', 'IPaddressdeleted', 1109177779) in /home/asturlib/public_html/includes/database.mysql.inc on line 125
This was related to somebody trying to login and a >5000 rows session table ( never cleared by cron?). Nothing but this error came up site became inusable.
I emptied the session table and that fixed it, but I wonder what was behind it. That's why I marked as bug.
Comments
Comment #1
chx CreditAttribution: chx commentedComment #2
stephenhendry CreditAttribution: stephenhendry commentedComment #3
bslade CreditAttribution: bslade commentedI don't understand this error:
Duplicate entry '0' for key 1 query: INSERT INTO sessions (uid, sid, hostname, timestamp) values(0, 'sessionIDisdeleted', 'IPaddressdeleted', 1109177779)
Assuming key 1 is the first index on "uid", it's not a primary or unique index. How can the database give an error for a duplicate entry when there's no uniqueness constraint in the index? Is this indicative of database corruption? Maybe some sort of mysql bug that gets exercised when there's a large number of duplicate entries in a non-unique indexed field? (eg. a gazillion zero's in the sessions.uid field for non-logged in Drupal clients)
On another site, after getting this error, they cleared out the sessions table (and maybe ran one of the consistency check commands) and this error went away (I'm a little fuzzy about exactly the db admin did)
Ben in DC
PublicMailbox at BenSlade dot com
Comment #4
stevryn CreditAttribution: stevryn commentedI had plenty of these errors and eventually found a post on here, look at the sequence table, that is where the "next" available number is determined. It's been a while so I dont exactly remember what I did, but check into sequences....
Comment #5
jairo.serrano CreditAttribution: jairo.serrano commentedThe same error, non-logged user, but the site it's down.
Fatal error: Duplicate entry '8cf2d0cfa89d20de162b37887cda4ba4' for key 1 query: INSERT INTO sessions (sid, uid, hostname, timestamp) VALUES ('8cf2d0cfa89d20de162b37887cda4ba4', 0, 'IPADDRESS', 1123014751) in /home/drupal/includes/database.mysql.inc on line 66
Comment #6
alexis CreditAttribution: alexis commentedAny update on this? I'm receiving a email message from cron saying:
Which I think is part of the same problem. I'm using Drupal 4.6.2 on Red Hat Linux Enterprise 3.
Regards!
Comment #7
tomski777 CreditAttribution: tomski777 commentedGot the same problem today. The whole site went down after deleting a user & even when I emptied the sessions table the error was still there.
I got things up again by changing a newly added session UID to 1 (it was previously at set at 0). Ita be good to know whats causing this...
Comment #8
tomski777 CreditAttribution: tomski777 commentedOk, I jumped the gun my above fix didn't work after all but this posting solved everything. Apparently its to do with there being to "user 0" in the users table.
Comment #9
tomski777 CreditAttribution: tomski777 commentedsorry- try this link:
/node/21120
Comment #10
magico CreditAttribution: magico commentedIs this still a problem?
Comment #11
magico CreditAttribution: magico commentedTo old and to quiet.
Comment #12
DiOne-1 CreditAttribution: DiOne-1 commentedYou must use auto_increment for the primary key ;)
Comment #13
snowstorm CreditAttribution: snowstorm commentedthis cron error showed up after my drupal db was migrated to a new server.
I already haver user '0' in my users table.
I fixed the problem by emptying my sessions table(sessions table stores all the users'(logged-in or non-logged-in session info)