Reputation: 15117
In rails, how can i get the seeds.rb to restart counting from 0 every single time?
Currently when i re-run: rake db:seed, the autoincrement columns keep increasing higher and higher.
Upvotes: 1
Views: 325
Reputation: 9146
May be you can use this
table_name = 'xyz'
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table_name}")
before seeding values in seed.rb
Upvotes: 6