Drupal:重复条目''对于键 2 查询:
我有一个脚本,可以以编程方式动态创建用户以与旧数据库同步。一段时间以来,它一直表现得很好。现在,在尝试插入用户时,突然开始出现重复键错误。确切的错误是:
<代码> 键 2 查询的重复条目“[email protected]”:INSERT INTO users (姓名、邮件、状态、通行证、已创建)...... 如果我尝试在那里查询,我可以直接从mysql
控制台复制此错误。所以这就是问题变得奇怪的地方。用户表中不存在条目“[email protected]'在哪里。因此,我对它如何生成重复输入错误感到困惑,因为数据库中没有包含此电子邮件地址的记录。
这是 mysql 控制台的直接复制/粘贴。敏感数据已更改以保护用户
mysql> INSERT INTO 用户(姓名、邮件、状态、通行证、创建)VALUES ('用户名', ' [电子邮件受保护]', 1, '加密密码', 1294946026);
错误 1062 (23000): 重复条目 '[电子邮件受保护]' 用于密钥 2
mysql> select * from users where mail='[电子邮件受保护]';
空集(0.00 秒)
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 '[email protected]' 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 '[email protected]' 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 INTO users (name, mail, status, pass, created) VALUES ('username', '[email protected]', 1, 'encryptedpassword', 1294946026);
ERROR 1062 (23000): Duplicate entry '[email protected]' for key 2
mysql> select * from users where mail='[email protected]';
Empty set (0.00 sec)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用 user_save 函数。
例如对于新闻用户:
You must use the user_save function.
For example for news users: