DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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

Top comments (4)

Collapse
 
coderljy profile image
KenntsuRinn

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
KenntsuRinn

Mysql is the same result.

Thread Thread
 
inayuky profile image
inayuky

The workaround is to disable 'spring' as follows.

  1. comment out gem 'spring' in the Gemfile
  2. execute "bundle install"

Details are below issue.
github.com/rails/rails/issues/3471...

I fixed this issue by the following PR.
github.com/rails/spring/pull/679

πŸ‘‹ Haven't Posted on DEV Yet?

Head over to our Welcome Thread and tell us a bit about yourself!