I'm attempting to setup seed data for my Rails application and am relying on the
id of every model as being a certain value. How do i tell the table to, after
MyModel.destroy_all to begin counting from again rather than where it left off?
The easiest way is most likely to decrease the entire table, recreate it after which seed it. This can be done with custom rake tasks.
Try something similar to this to decrease your table:
desc "Drop MyModel table" task :drop_my_model => :environment do connection = ActiveRecord::Base.connection connection.execute("drop table my_models") end end
you'll be able to rake
$ rake drop_my_model $ rake db:migrate:up VERSION=my_version