How to delete all data from all tables in Rails?

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

    You can have finer control with:

    rake db:drop:all
    

    And then create the database without running the migrations,

    rake db:create:all
    

    Then run all your migrations,

    rake db:migrate 
    

    You can also do:

    mysqladmin drop databasename
    

提交回复
热议问题