How to delete all data from all tables in Rails?

前端 未结 16 2397
情歌与酒
情歌与酒 2020-12-07 15:23

I can do Post.delete_all to delete all my posts, but what if I want to delete all posts, comments, blogs, etc.?

How do I iterate over all my models and

16条回答
  •  [愿得一人]
    2020-12-07 16:14

    In Rails 6, you can do rails db:truncate_all to remove all data without dropping any tables.

    If you would like to seed your db after that, you could also do rails db:seed:replant to truncate all data and seed database

提交回复
热议问题