Rails Migration for ID Column to Start at 1,000 and Autoincrement Up From There?

前端 未结 2 1563
醉酒成梦
醉酒成梦 2021-01-11 12:44

I\'d like the ID\'s of my Order model to start at 1000, and count up autoincrementally from there.

Can this be done via migration?

2条回答
  •  [愿得一人]
    2021-01-11 13:00

    This has not been tested and I am not sure what db you are using.

    create_table(:order, :id => false) do |t|
       t.integer :id, :options => 'PRIMARY KEY', :default => 1000
    

    or if you already have the table try this migration

    def change
      execute "ALTER TABLE orders AUTO_INCREMENT = 1000"
    end
    

提交回复
热议问题