Truncate table(s) with rails console

前端 未结 9 1338
北恋
北恋 2021-02-02 05:51

I have this testingdatabase which, by now, is stuffed with junk. Now I\'ve done a few Table.destroy_all commands in the rails console which deletes all records and dependencies

9条回答
  •  醉梦人生
    2021-02-02 06:10

    You could also do rake db:rollback STEP=3 RAILS_ENV=test

    where 3 represents the number of migrations that you have in db/migrate. In example: If I have in

    db/migrate
    20140121065542_create_users.rb
    20140121065710_create_profiles.rb
    20140121065757_create_articles.rb
    20140121065900_create_comments.rb
    20140121065929_create_categories.rb
    

    So I have 5 migrations in total to remove. If I do rake db:rollback STEP=5 RAILS_ENV=test all the tables will be drop from my TEST database and if I remove RAILS_ENV=test than all the ENVIRONNMENT (production, test, development) tables will be delete and it cleans also db/shema.rb file from it's migration datas.

提交回复
热议问题