Hello there,
I'd like to change the minimum for the id of created objects from 1 to 1000. So when I create in rails my first model object it gets the ID 1000 and not 1.
Is there a way to set this in the schema/migration files?
Hello there,
I'd like to change the minimum for the id of created objects from 1 to 1000. So when I create in rails my first model object it gets the ID 1000 and not 1.
Is there a way to set this in the schema/migration files?
I am not familiar with MySQL, but for Postgres you can do something like this in your migration file:
class CreateCustomers < ActiveRecord::Migration
def self.up
create_table :customers do |t|
t.string :name
t.timestamps
end
execute "SELECT setval('customers_id_seq', 1000);"
end
Note that the execute method call is made outside the create_table block.
For MySQL use
class CreateCustomers < ActiveRecord::Migration
def self.up
create_table :customers do |t|
t.string :name
t.timestamps
end
execute "ALTER TABLE customers AUTO_INCREMENT = 1000;"
end
This will have your auto_increment field (id) start at value 1000.