简体   繁体   English

如何从零重新启动seeds.rb列?

[英]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? 在Rails中,我如何才能使seeds.rb每次从0开始重新计数?

Currently when i re-run: rake db:seed, the autoincrement columns keep increasing higher and higher. 目前,当我重新运行:rake db:seed时,autoincrement列会越来越高。

May be you can use this 也许你可以用这个

table_name = 'xyz'
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table_name}")

before seeding values in seed.rb 在seed.rb中播种值之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM