Set/Change Rails id auto increment value
-
27-10-2019 - |
Question
Is there a way for me to set the increment value of id in Rails? Instead of +1, to be +10 (or some other function I specify).
In MySQL there is an option @@auto_increment_increment. Is there a way to set in Rails through ActiveRecord? I am working with both Postgres.
Solution
Check the Rails 3.x guide on migrations: http://guides.rubyonrails.org/migrations.html
There is a example where they hardcode some sql
class SomeMigration < ActiveRecord::Migration
def up
execute <<-SQL
ALTER TABLE xxx
SQL
end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow