Beim Erstellen eines Projekts
rails new sample_app -d postgresql
Wo soll ich sagen?
rails new sample_app -D postgresql
Weil es war, wurde Posgre nicht gesetzt.
In Gemfile
# Use postgresql as the database for Active Record
gem 'pg'
Ich möchte, dass Du
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
Es war.
Ich frage mich, ob sqlite3 die Standardeinstellung ist.
https://qiita.com/rubys8arks/items/0749d6fa73e88d3d381c Lassen Sie es uns in Bezug darauf ändern.
Da Posgre selbst installiert ist,
Bei sqlite3
in der Gemfile
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
Wechseln Sie zu "Bundle-Installation" und führen Sie sie aus.
In diesem Zustand kann Rails db: create
nicht ausgeführt werden
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'] %>
Hier weggelassen
-> % bin/rails db:create
Created database 'sample_app_development'
Created database 'sample_app_test'
Recommended Posts