Copying users from one Drupal installation to another

jenna.tollerson - June 8, 2009 - 19:16

For various reasons I needed to do a clean installation of an existing Drupal site. Ditch all the old nodes and configuration, but I just wanted to keep one thing: the users.

So I did a brand new installation of 5.x, and before I created user #1, I copied my {users} table from the old installation to the new installation. I logged in with my user #1 credentials from the old site, and it worked! I though I was home free, and I did a ton of work installing new modules and configuring the new site.

Then I tried to create a brand new user, and I got this MySQL error:

user warning: Duplicate entry '1' for key 1 query: INSERT INTO users (name, mail, pass, init, status, uid, created) VALUES ('jennatestaccount', 'jenna@example.com', 'ca4a3e565ed24bd7567e3d13571833ad', 'jenna@example.com', 1, 4, 1244487829) in /home/thom/www/uc.fretsmaster.com/includes/database.mysql.inc on line 174.

Each user I try to create, I get the same message, with the Duplicate entry '1' increased by one each time. Obviously, the system is trying to create user ids that are already there because it doesn't know about my dozens of users already in the {users} table. So what did I miss, and how can I make this work?

Thanks in advance for any assistance.

hi jenna, cant see answer

nirbhasa - June 8, 2009 - 19:27

hi jenna, cant see answer offhand, but a couple of ideas:

1. check that the uid column on your table is set to auto_increment
2. How does auto_increment work? does it increment on from the hightst value of uid or the last value? If the latter, then perhaps sort your users table in order of increasing uid
3. Check the user_import module, the code might contain a couple of pointers

You can do it with PHPMyAdmin

spookypld - June 8, 2009 - 20:22

Well, You're trying to achieve two different goals and so, there are few solutions. (sorry my english is bad).

You can't create brand new user, because there is already user with uid=1 in `users` table. You need to delete it first (or You can to login with Your's old user password).

You've to do one more additional step which is going to be table `sequences`. This is very important table in whole Drupal database, because it rules with all Drupal IDs structure. Well, it's little bit sophisticated to explain. However the reason this node is because it shows what will be next node, revision, user etc. number that You're trying to create. I suspect there is comflict between this table and users table. Sequences is set to `0` on fresh Drupal installation. Then, when You're creating first user it becomes '1'. Every next user is adding value field `uid` in `sequences`. You must set it to the highest uid from `users` table.

the `sequences` table

jenna.tollerson - June 8, 2009 - 20:41

That was the missing piece I didn't know about - the `sequences` table. I set the users_uid to the highest uid from my users tables and voilà! I was able to create users again. Fantastic!

Thanks so much for all the help everyone. I've been working with Drupal for a while now and it's amazing to see how much I still have to learn about the basics. :)

 
 

Drupal is a registered trademark of Dries Buytaert.