Closed (works as designed)
Project:
Drupal core
Version:
7.x-dev
Component:
user system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
5 Jul 2011 at 10:43 UTC
Updated:
15 Feb 2021 at 17:29 UTC
Jump to comment: Most recent
Comments
Comment #1
ParisLiakos commentedComment #2
regginos commentedI just noticed that too. Trying to insert into that table using db_insert() gives an error. Why does the "users" table have no auto_increment field?
Comment #3
droplet commentedI guess one of the reason is innodb auto-increment isn't reliable.
eg. while hit error, innodb keeps increase ONE in auto-increment but MyISAM don't.
Comment #4
regginos commentedSo how is the uid in the "users" table desided? I tried to create a couple of test users and they are given quite strange uid's and there are gaps in the uid's (users have uid's: 0,1,14,19,20. Why not 3,4, etc.?).
Comment #5
marcingy commentedThe next value is pulled from the sequences table this is by design. Calling drupal_write_record will increment to next available sequence if no uid is provided.
Comment #6
regginos commentedSo I should call drupal_write_record instead of db_insert (I want to create some specific users during install of a module I am writing). Am I correct?
To honest, I tried
before adding the new users, but doesn't work either.
Comment #7
marcingy commentedYou can simply call user_save I believe and pass in the appropriate data via that api. All enitity operations should user the drupal api.
eg
This would create a user with called name, with a given email adress, a random password and make them active.
Comment #8
marcingy commentedYou can even amend account to be
However this will fail if uid 4 already exists and to be honest I would never build a module based on needs specific uids beyond 0 and 1, the uids available are going to be inconsistent. The only time this makes sense is doing a data import and there is a need to preserve data. If you need specific users you should define roles and assign the role to a user and then test if the give user has access to do somthing via user_access function.
Comment #9
regginos commentedThank you, marcingy! Your comments have been very helpfull to me. Yes, I agree that the only time this makes sense is data import to those users accounts. I need them as dummy accounts to store a value in a new field the module creates in the users table. Those dummy user-accounts just represent a some robots that will function in my site and will never be used for log-in. They are created with status "0". I think it makes sense.
There is something else bothering me: as a new programmer and complete novice in Drupal how was I supposed to find out about the existence of the user_save() function? Searching drupal for "add new user" or "adding new users in database" doesn't give very helpfull results. Of caurse when you know the function's name, you can easily find it's documentation. Is there a nice way to see what functions are available in drupal API?
Comment #10
marcingy commentedNo problem glad the above info was useful. Drupal has an online reference http://api.drupal.org/api/drupal and specifically you are likely to be interested in http://api.drupal.org/api/drupal/functions/7 and http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7. Also the examples module is really helpful reference point http://drupal.org/project/examples.
Comment #11
ParisLiakos commentedstill...i dont get why node is AUTO_INCREMENT and user is not.....seems inconsistent to me...anyways
Comment #12
marcingy commentedYou can find more info here http://drupal.org/node/356074
Comment #13
W.M. commentedUser table must have its own auto-increment. This issue must be taken seriously. On one site of mine, I had the Uid jump from 13 to 1130 because of the shared auto-increment value with other Drupal core modules.
Comment #14
drupalfan2 commentedHow can I write a patch for this problem for Drupal 8/9?
uid should be consistent without gaps. Any idea for a patch?