Kamilski81
Kamilski81

Reputation: 15117

How do I restart the seeds.rb columns from zero?

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

Answers (1)

Pritesh Jain
Pritesh Jain

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

Related Questions