[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.

Ruby on Rails | ルビーオンレイルズ
  1. rake db:reset
  2. 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:

  1. Drop all tables
  2. 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:

  1. Drop all tables
  2. 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.