开发者

How to specify :primary_key starting value in rails schema migration?

开发者 https://www.devze.com 2022-12-21 03:39 出处:网络
I have a postgres table and a schema t开发者_如何学运维hat creates a primary id (sequence) that auto increments by 1. How do I specify the starting value? I am happy with the increment value. Here is

I have a postgres table and a schema t开发者_如何学运维hat creates a primary id (sequence) that auto increments by 1. How do I specify the starting value? I am happy with the increment value. Here is my schema migration:

create_table "ServiceProvider", {:primary_key => :ID} do |t|
  t.integer "ID",                       :null => false
end

Thank you


Use this option :

create_table "ServiceProvider",:options => "AUTO_INCREMENT = 1234" do |t|
  ...
end

But be carefull, this wouldn't work with ALL database management systems. I know this should work with MySQL but you might want to double check for postgres.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号