A rails app uses SQlite3 as a built-in database.
The following command will create a new rails project with SQlite3:
rails new project
If you want to change the dbname
with your selected db in the command below:
rails new project -d dbname
gem install pg
cd Project
nano Gemfile
Replace the following line:
gem 'sqlite3'
With:
gem 'pg'
Once all changes are made, run
bundle install
to update theGemfile.lock
file.
database.yml
fileThe
databse.yml
file has the following commands:
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
database.yml
.set postgresql
as adapter
set unicode as encoding
set your application name as database name
set pool = 5
The final development version will be:
development:
adapter: postgresql
encoding: unicode
database: yourApp_development
pool: 5
username: username
password:
timeout: 5000
Then, repeat all the steps for test:
test:
adapter: postgresql
encoding: unicode
database: youApp_test
pool: 5
username: username
password:
timeout: 5000
rake db:setup
...
...some messages...
...
rake db:migrate
Try all the above commands, one by one, in the terminal below:
RELATED TAGS
CONTRIBUTOR
View all Courses