Ruby on Rails: Change database from SQLite to PostgreSQL.

rails new appName --database=postgresql

1. Edit the Gemfile.

bundle install

2. Edit config/database.yml file

default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

development:
<<: *default
database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

production:
<<: *default
database: db/production.sqlite3
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: postgres #username you provided when installing postgresql. By default its postgres(if you did not provide any)
password: xxxx #password you provided when installing postgresql

development:
<<: *default
database: hello_rails_development #name of your database

test:
<<: *default
database: hello_rails_test #name of your database

production:
<<: *default
database: Hello_production
username: Hello
password: <%= ENV["FRIENDLIST_DATABASE_PASSWORD"] %>

3. Create the database.

rails db:create

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abigael Nyakara

Abigael Nyakara

30 Followers

Technical Writer with a knack for explaining hard things in an easy way. All things tech!