Forrest logo
back to the rails tool

rails-db:tldr:44047

rails-db: Rollback the last migration.
$ rails db:rollback
try on your machine

The rails db:rollback command is used in Ruby on Rails applications to reverse the most recent database migration.

When a migration is generated and run using the rails db:migrate command, it modifies the database schema by adding or modifying tables, columns, indices, etc. The migration files are typically stored in the db/migrate directory of a Rails application.

The rails db:rollback command allows you to rollback the most recent migration, undoing the changes made to the database schema. When you run this command, Rails looks for the last migration that was previously run and executes its down method. This method contains the code to reverse the changes made by the corresponding up method in the migration file.

In addition to rolling back the schema changes, rails db:rollback also updates the schema_migrations table in the database, marking the previously rolled back migration as not applied.

It's important to note that rails db:rollback should be used with caution as it can lead to data loss or inconsistency if not used properly.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the rails tool