Joe
Joe

Reputation: 15349

How to set auto increment by 1 on a table in your migration script

How to set auto increment by 1 on a table in your migration script

ALTER TABLE Table_name AUTO_INCREMENT = 1;

Is it possible to mention this during table creation or after that, in your DB migration scripts.

Upvotes: 0

Views: 600

Answers (1)

Yanhao
Yanhao

Reputation: 5294

Maybe there are better solutions. Otherwise you can run raw SQL statements in migration scripts like this:

ActiveRecord::Base.connection.execute("ALTER TABLE Table_name AUTO_INCREMENT = 1")

Upvotes: 1

Related Questions