---
title: "Rails 6 has added a way to change the database of the app"
description:
  "It is possible to change the database configuration using a simple command"
canonical_url: "https://www.bigbinary.com/blog/rails-6-has-added-a-way-to-change-the-database-of-the-app"
markdown_url: "https://www.bigbinary.com/blog/rails-6-has-added-a-way-to-change-the-database-of-the-app.md"
---

# Rails 6 has added a way to change the database of the app

It is possible to change the database configuration using a simple command

- Author: Prathamesh Sonpatki
- Published: April 30, 2019
- Categories: Rails 6, Rails

Rails allows us to use different databases using the `database.yml` config file.
It uses sqlite3 as the default database when a new Rails app is created. But it
is also possible to use different databases such as MySQL or PostgreSQL. The
contents of `database.yml` change as per the database. Also each database has a
different adapter. We need to include the gems `pg` or `mysql2` accordingly.

Before Rails 6, it was not possible to change the contents of `database.yml`
automatically. But now a
[command has been added](https://github.com/rails/rails/pull/34832) to do this
automatically.

Let's say our app has started with sqlite and now we have to switch to MySQL.

```bash
$ rails db:system:change --to=mysql
    conflict  config/database.yml
Overwrite /Users/prathamesh/Projects/reproductions/squish_app/config/database.yml? (enter "h" for help) [Ynaqdhm] Y
       force  config/database.yml
        gsub  Gemfile
        gsub  Gemfile
```

Our `database.yml` is now changed to contain the configuration for MySQL
database and the `Gemfile` also gets updated automatically with addition of
`mysql2` gem in place of `sqlite3`.

This command also takes care of using
[proper gem versions](https://github.com/rails/rails/pull/35522) in the Gemfile
when the database backend is changed.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-6-has-added-a-way-to-change-the-database-of-the-app)
