user warning: Duplicate entry '0' for key 1 query: INSERT INTO mysite

LanceLight - June 13, 2008 - 23:11
Project:MySite
Version:HEAD
Component:Code
Category:support request
Priority:critical
Assigned:Unassigned
Status:closed
Description

I've installed this module on 2 different fresh drupal installs using both HEAD and Released versions and every single time I click on "Page Settings" in the Configuration area it gives this error:
user warning: Duplicate entry '0' for key 1 query: INSERT INTO mysite (uid, created, status, title) VALUES (0, 1213397668, 1, 'My Homepage') in /home/usersdir/public_html/includes/database.mysql.inc on line 172.

I have deleted ID 0 in the mysite table over and over and every time I refresh that Page Settings page, it always re-makes ID 0 even if it already exists. My guess is that it shouldnt be inserting anything at all. Why is it trying to insert ANYTHING at all during a simple page view of a configuration setting? I thought maybe it was the "default user ID" for default settings, but its not. I have it set to user ID 1 for that (which is the admin user). I've tried setting it to a regular user also but no matter what I do, this page always tries to insert an ID 0. I have not looked at the code at all to find out why its running inserts during a view process. I'm surprised no one else has reported this error. It makes it impossible for the admin to define default settings for mysite.

#1

LanceLight - June 13, 2008 - 23:22

O, 1 other note. It does this on ANY link inside admin/settings/mysite/edit which includes the "Page Settings" link I mentioned earlier. So even clicking "Content Layout" will give the same error. If I delete ID 0, it always re-adds ID 0. Here is what it's adding to the table for ID 0:

uid created updated status confirm title layout style format theme message
1036 1213386759 1213386759 0 0 tony1 default default default NULL NULL
1 1213387027 1213396844 0 0 admin stacks default default aveguy NULL
0 1213397530 1213399117 1 0 My Homepage default default default NULL NULL <--------------------------
1095 1213395325 1213395329 0 0 asdf default default default aveguy NULL
1096 1213396705 1213396705 0 0 asdf2 default default default NULL NULL

#2

agentrickard - June 16, 2008 - 14:00

HEAD is not for production use.

Which release version?

#3

agentrickard - June 16, 2008 - 14:17

ID 0 is used, by the way, to store the default settings and content for all users. It is being created because it needs to be there so you can make changes to it. THe routine that does this is part of the upgrade from 5.2 (which did not allow multiple pages) to 5.3, which does.

You are running a fresh install and not an update, right? And if an update, you _did_ run update.php, right? This problem might occur if the {mysite_page} table does not exist.

#4

LanceLight - June 16, 2008 - 18:22

I used the HEAD version purely to see if the problem I have had been fixed or not. The release version I'm actually trying to use is :5.x-3.2 2008-Apr-27. The steps I take to install/uninstall are as follows:

Drop all mysite* tables
Delete all mysite* rows in system table
Delete mysite module dir
Download new module
Install
Attempt to create default settings.
Every single time I enter a page with default settings it tries to create this UID 0 entry. I have never once tried to run update.php since it's NOT an update. Its a FRESH install each time. It's like something somewhere other than the places I've been cleaning out is telling it to try to insert things while VIEWING simple config settings. I would expect it to only do that if I try to run like an update.php file and not by viewing something. BTW, the mysite_page table does exist and it has rows in it but the error still persists. What line is telling it insert UID 0 and why? It's like it's missing a check to see if UID 0 even exists before attempting to insert it but I have no idea where that insert is taking place.

#5

agentrickard - June 16, 2008 - 21:44

Please mind your tone. No one else -- including me -- has ever seen this behavior.

This routine exists for a very good reason -- to prevent errors when someone starts creating / editing a collection but never hits submit. This routine actually avoids a lot of errors.

The function is question is:

http://therickards.com/api/function/mysite_create_account/MySite

Which, if you read the API, leads to the following:

http://therickards.com/api/function/mysite_create_account/MySite/referen...

http://therickards.com/api/function/mysite_edit/MySite
http://therickards.com/api/function/mysite_content/MySite

mysite_edit() starts on line 914 of the mysite.module
mysite_content() starts on line 1000.

I cannot duplicate the error. The routine is likely running because mysite_get() keeps returning -1 (indicating no collection exists), but I don't know why that would be.

Are you doing anything out of the ordinary, like table prefixing or multisite installs?

#6

LanceLight - June 16, 2008 - 23:20

I started poking around myself and I've spent the last 3 hours trying to figure out why mysite_get() is returning -1. With you mentioning the same thing then I must be on the right track somewhere. I did try to use db_error() to see if it was a bad query somewhere but got nothing back on that. Most likely because I am not looking at the right query maybe. It must be something database related, I just cant figure out what it is. I even checked to see if collation was set to utf8_general_ci which it is. I dont have any prefixed tables or anything funky like that either.

// Add default content to the user page if it has been set.
$get = mysite_get(0);

I print_r'r $get right here in the mysite_create_account() function and it comes back with a -1 instead of the default uid 0 object. I know uid exists, I showed it in the rows above in the first post here so I dont know why its not picking it up. So whatever is causing it to come back as -1 is why it's also trying to insert UID 0 which already exists. This is why default settings dont work at all and why it shows the error of trying to insert a record that already exists. So once I can get it to recognize that UID 0 does actually exist, this error will go away and default content "should" work I think.

#7

LanceLight - June 16, 2008 - 23:41

After more digging I finally figured out what it was. My user table did not have a user with UID of 0. I dont know why it was missing but once I added it with a status of 0 and a UID of 0, this error goes away and default settings now work. So my suggestion would be to add a check to see if UID 0 exists, if not, go ahead and create it since it's suppose to be there to begin with. I think drupal comes with uid 0 as a blank user set to status 0.

#8

agentrickard - June 17, 2008 - 14:16
Category:bug report» support request
Status:active» closed

Right. That explains a lot.

User 0 in the {users} table is used as a surrogate for all anonymous users. If it disappears, all manner of issues will arise. In this case, it caused the JOIN to fail.

Good work!

#9

djpumpkin - August 13, 2008 - 17:34

I had exactly the same issue with a clean install of Drupal. Spent the last 2 days trying to figure this out. I have no idea how I lost UID 0 but it was missing. By inserting a blank row into my users table - with no values - it fixed the error.

Thanks for posting on this issue - there's no way I would have solved this on my own!!

 
 

Drupal is a registered trademark of Dries Buytaert.