[Ruby on Rails] How to Initialize and Reset Database ~ rake db:reset and rake db:migrate:reset
Tadashi Shigeoka · Sat, October 7, 2017
I’ll introduce two methods for resetting the database (DB) in Ruby on Rails.
- rake db:reset
- rake db:migrate:reset
When You Want to Delete All DB Records
rake db:reset
Use this command.
The process flow for db:reset is:
- Drop all tables
- Recreate tables based on db/schema.rb
When You Want to Delete All DB Records and Reflect Table Definition Changes
rake db:migrate:reset
Use this command.
The process flow for db:migrate:reset is:
- Drop all tables
- Execute all migration files under db/migrate/ to recreate tables
I Often Use db:migrate:reset
Personally, I often use rake db:migrate:reset because it completes all migrations as well.
That’s all from the Gemba, where I wanted to reset the database (DB) in Ruby on Rails.