---
title: "Rails 6.1 raises error on rollback when using multiple database"
description:
  "Rails 6.1 raises on db:rollback for multiple database applications"
canonical_url: "https://www.bigbinary.com/blog/rails-6-1-raises-on-db-rollback-for-multiple-database-applications"
markdown_url: "https://www.bigbinary.com/blog/rails-6-1-raises-on-db-rollback-for-multiple-database-applications.md"
---

# Rails 6.1 raises error on rollback when using multiple database

Rails 6.1 raises on db:rollback for multiple database applications

- Author: Srijan Kapoor
- Published: August 12, 2020
- Categories: Rails 6.1, Rails

Rails 6.1 adds support to handle `db:rollback` in case of multiple database
application.

Prior to this change, on executing `db:rollback` Rails used to rollback the
latest migration from the primary database. If we passed on a `[:NAME]` option
along with to specify the database, we used to get an error. Check out the
[issue](https://github.com/rails/rails/issues/38513) for more details.

#### Rails 6.0.0

```ruby
> rails db:rollback:secondary

rails aborted!
Don't know how to build task `db:rollback:secondary` (See the list of available tasks with `rails --tasks`)
Did you mean?  db:rollback
```

Staring with Rails 6.1, we need to pass the database name along with
`db:rollback:[NAME]` otherwise a `RuntimeError` is raised.

#### Rails 6.1.0

```ruby
> rails db:rollback

rails aborted!
You're using a multiple database application. To use `db:migrate:rollback` you must run the namespaced task with a VERSION. Available tasks are db:migrate:rollback:primary and db:migrate:rollback:secondary.

> rails db:rollback:primary

== 20200731130500 CreateTeams: reverting ======================================
-- drop_table(:teams)
   -> 0.0060s
== 20200731130500 CreateTeams: reverted (0.0104s) =============================
```

Check out the [pull request](https://github.com/rails/rails/pull/38770) for more
details on this.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-1-raises-on-db-rollback-for-multiple-database-applications)
