db_insert() returns wrong key I'm trying to migrate from drupal_write_record() to db_insert() / db_update(),
but db_insert() returns a weird key instead of the last inserted key.

On an empty table, I'm doing an insert, and instead of real row number (suppose to be 1, right?), I'm getting a wrong one.

$fields['created'] = REQUEST_TIME;
$fields['uid'] = 1;
$insert = db_insert('table')-&gt;fields($fields);
$last_insert_id = $insert-&gt;execute(); // suppose to be 1, but = 43587087


Any ideas?
Thanx.
The autonumber isn't related to the number of records in the table, but rather the AUTO_INCREMENT value of the table's primary key column.

If you have a completely new table, and add 100 rows, the next ID will be 101. If you just remove all the rows in that table the next ID will still be 101, unless you TRUNCATE the table, or reset the AUTO_INCREMENT column.

For an easy way to test, fire up your preferred DB client, and insert a record into the database. If you get 1 as the next insert ID, there's a bug with your Drupal installation/DB engine. If not, it's just what's mentioned above.