When creating a project
rails new sample_app -d postgresql
Where to say
rails new sample_app -D postgresql
PostgreSQL was not set because it was.
In Gemfile
# Use postgresql as the database for Active Record
gem 'pg'
I want you to be
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
It was.
I wonder if sqlite3 is the default one.
https://qiita.com/rubys8arks/items/0749d6fa73e88d3d381c Let's change it with reference to this.
Since PostgreSQL itself is installed,
At sqlite3
in the Gemfile
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
Change to and do bundle install
.
In this state, rails db: create
cannot be done
bin/rails db:create
rails aborted!
LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile.
before
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
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
after
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: sample_app_development
test:
<<: *default
database: sample_app_test
production:
<<: *default
database: sample_app_production
username: sample_app
password: <%= ENV['SAMPLE_APP_DATABASE_PASSWORD'] %>
Omitted here
-> % bin/rails db:create
Created database 'sample_app_development'
Created database 'sample_app_test'
Recommended Posts