How to delete all data from all tables in Rails?

前端 未结 16 2435
情歌与酒
情歌与酒 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:24

    If you simply want to start fresh with a fresh set of empty tables, you can first ensure you have an up-to-date definition of the schema in db/schema.rb:

    rake db:schema:dump
    

    and then:

    rake db:schema:load
    

    which has the effect of dropping tables and then re-creating them, without running through your entire battery of migrations.

提交回复
热议问题