How to set an existing database field to auto increment I have an existing database that has an id field that is an unsigned integer with a length of ten (and is set as the primary key). I would like to write an update to change this field so that it auto increments. How would I go about doing that? I am familiar with writing updates, just haven't done one like this before. I am doing this with Drupal 7.
I found the solution I was looking for here. Below is the relevent part.

For example, suppose you have:

$schema['foo'] = array(
  'fields' =&gt; array(
    'bar' =&gt; array('type' =&gt; 'int', 'not null' =&gt; TRUE)
  ),
  'primary key' =&gt; array('bar')
);


and you want to change foo.bar to be type serial, leaving it as the primary key. The correct sequence is:

db_drop_primary_key('foo');
db_change_field('foo', 'bar', 'bar',
  array('type' =&gt; 'serial', 'not null' =&gt; TRUE),
  array('primary key' =&gt; array('bar')));