开发者

Drupal: Duplicate entry '' for key 2 query:

I have a script that is programatically creating users on the fly to sync with an old database. It's been puring along quite nicely for a while. Now all of the sudden It started erroring out with a duplicate key error when trying to insert a user. the exact error is:

Duplicate entry 'user@email.com' for key 2 query: INSERT INTO users (name, mail, status, pass, created).....

And I can replicate this error directly from the mysql console if i try the query there. So this is where the issue gets weird. the entry 'user@email.com' does not exist in the user table any where. Thus I am perplexed at how it is generating a duplicate entry error since there is no record in the database with this email address.

here is a direct copy/paste of the mysql console..sensitive data has been changed to protect the user

mysql> INSERT INT开发者_Python百科O users (name, mail, status, pass, created) VALUES ('username', 'user@email.com', 1, 'encryptedpassword', 1294946026);

ERROR 1062 (23000): Duplicate entry 'user@email.com' for key 2

mysql> select * from users where mail='user@email.com';

Empty set (0.00 sec)


You must use the user_save function.

For example for news users:

$user = user_save( null, array( 'name' => 'the name' , 'mail' => 'the user mail'));


  • Export the table and recreate it locally and try the insert again.
  • Maybe there's an encoding issue? Try search for all users with the same domain to see if there are similar entries.
  • Use the Devel module's query table to see what's actually happening within Drupal as well.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜