I just noticed something weird in a site I'm working on. The first account is user/1 as usual. A second account I created two weeks later is user/20, and a third one a couple days later is user/32. Etc. Two accounts I just created right after each other are numbered consecutively as expected.

There are no custom modules modifying the registration process or anything. I wonder what could cause this, and if there's something I need to fix.

  • 1
    Is it a public site where users can create their own accounts? Is there any module that deletes accounts created by spammers, or somebody else who is administering that site, and who could delete accounts created by spammers?
    – avpaderno
    Commented Aug 18, 2012 at 12:33
  • I started on a local server, so the gap between uid 1 and 20 can't be explained by something like that. The site does accept user registrations, but it's running on an unadvertised subdomain and we haven't had any spam registrations. No account deletion modules. Could it have anything to do with moving the site to another hosting environment?
    – arjan
    Commented Aug 18, 2012 at 12:44

2 Answers 2


So, it turns out this is indeed normal since Drupal 7: the users table is not auto-increment but uids are created with a sequences API that is shared with actions and batch jobs. Uids can therefore be non-consecutive.

Several reasons for changing back from auto-increment table in D6 are pointed out here by chx.

(From reading chx's response to this blog post)


I noticed the same, I had some gaps between new user ids that even reached at some points 1000 because I was relying on the batch API at my site which shared the same incremental ids for its jobs with the user table. Here is a tested solution that ensures that user id's will always increase by one.

function MYMODULE_user_presave(&$edit, $account, $category) {
  if (isset($account->is_new) && !empty($account->is_new)) {  
   $account->uid = db_query('SELECT MAX(uid) FROM users')->fetchField() + 1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.