# Migrations - How to set auto increment?

**URL:** <https://www.ruby-forum.com/t/migrations-how-to-set-auto-increment/54257>\
**Category:** Rails\
**Created:** [February 28, 2006, 12:21am UTC](https://www.ruby-forum.com/t/migrations-how-to-set-auto-increment/54257 "2006-02-28T00:21:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vamsee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/59ef9b/32.png) [@Vamsee](https://www.ruby-forum.com/u/Vamsee)\
**Post date:** [February 28, 2006, 12:21am UTC](https://www.ruby-forum.com/t/migrations-how-to-set-auto-increment/54257/1 "2006-02-28T00:21:25Z")

</div>

Hi all,

I’d like to know how can I set a field to auto increment in migrate  
scripts. In mysql, it’s auto\_increment, and in postgresql, it’s serial.  
How can I make a migrate script which works in both places?

TIA,  
Vamsee.

---

<div class="post-metadata">

**Author:** ![Vamsee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/59ef9b/32.png) [@Vamsee](https://www.ruby-forum.com/u/Vamsee)\
**Post date:** [February 28, 2006, 12:26am UTC](https://www.ruby-forum.com/t/migrations-how-to-set-auto-increment/54257/2 "2006-02-28T00:26:34Z")

</div>

Sorry, I forgot to tell you that I want auto increment for a field other  
than the primary key (id).

---

<div class="post-metadata">

**Author:** ![Vamsee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/59ef9b/32.png) [@Vamsee](https://www.ruby-forum.com/u/Vamsee)\
**Post date:** [February 28, 2006, 5:50pm UTC](https://www.ruby-forum.com/t/migrations-how-to-set-auto-increment/54257/3 "2006-02-28T17:50:29Z")

</div>

Vamsee wrote:

> Sorry, I forgot to tell you that I want auto increment for a field  
> other than the primary key (id).

mysql\> create table test (  
a int auto\_increment primary key,  
b int unique auto\_increment  
);  
ERROR 1075: Incorrect table definition; There can only be one auto  
column and it must be defined as a key

MySQL doesn’t seem able.
