How to reset the database for a rails application?

less than 1 minute read

When working on Ruby on Rails projects, there are times when we need to reset the database to its initial state, clearing all existing data and schema migrations.

This process is essential for development, testing, or troubleshooting purposes.

Understanding the db:reset command

The rails db:reset command will drop the database and set it up again.

To reset the databse run:

$ rails db:reset

This is equivalent to executing the following commands

rails db:drop db:setup

Caution: This command will drop the database resulting in data loss. Please ensure you are executing this command in the correct environment and have a backup of the data if required.

References