How to assign uid in "users" table with imported users? I am using Drupal 7.

I am using the Migrate module to migrate a list of users from an external user database table into the Drupal "users" table. The problem is that the Drupal "users" table has a numerical "uid" field, which does not exist in my external database users table.

Could someone please tell me of a way to assign a unique uid to the users table everytime I map a row using Migrate?

For example, right now I have, in the "users" database:

0
1 root ...
//external users start here
2 user1 ...
3 user2 ...
4 user3 ...


Essentially I have would like to start at 2 and continue for each user I migrate over to the "users" table.

More specifically, how I would modify/add a line to the following so that the code can auto generate unique ID's starting from 2? Would the following code be a viable option? If so, where would be the appropriate place to update $counter?

$counter = 2;
$this-&gt;addFieldMapping('uid', '$counter');


Thanks.

EDIT:

If I were to use the following SQL statement to do the user migration, would it be a good idea? If it is also a viable option, how might be able to create unique "uid" for insertion into the "users" table?

INSERT INTO users (uid, name, mail,pass,...) SELECT uid, oldusername, email, md5(clear_password),... FROM old_users_table;


Thanks.
Inserting data directly into Drupal tables is generally a bad idea (until you are familiar enough with the database schema to know what you're doing). For programmatically inserting users there are functions like user_save() and drupal_form_submit() that you can use.

As for generating the unique uid: if you can't just provide incremental values in the data insertion loop then you might be able to use the following code instead (copied from user_save() function):

$account-&gt;uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')-&gt;fetchField());


I'm not familiar with the Migrate module so I don't have more specific advice to offer currently, but the above info and links should be helpful.