DEV Community

Cover image for How to change the database in a Rails application ?
Alef Ojeda de Oliveira
Alef Ojeda de Oliveira

Posted on

How to change the database in a Rails application ?

Hello guys !

sometimes I came across the need to change the application's database, because many times we start with a study project with Sqlite3 and then the project ends up getting bigger with another need and then we decided to change to another one like (PostgreSQL, MySQL, etc ...)!

So here's a nice little tip:

rails db:system:change --to=postgresql
rails db:system:change --to=mysql
rails db:system:change --to=sqlite3
rails db:system:change --to=oracle
rails db:system:change --to=frontbase
rails db:system:change --to=sqlserver
rails db:system:change --to=jdbc
Enter fullscreen mode Exit fullscreen mode

**obs: only works from rails version 6 onwards

Discussion (3)

Collapse
coderljy profile image
JianYueLin

But when I run the command,

rails db:system:change --to=postgresql

it says that

Running via Spring preloader in process 15186
invalid option: --to=postgresql

my env:

ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
Rails 6.1.4.1

Collapse
nemuba profile image
Alef Ojeda de Oliveira Author

Strange here it worked, tested other databases?

Collapse
coderljy profile image
JianYueLin

Mysql is the same result.