[Ruby] ActiveRecord :: AdapterNotSpecified 데이터베이스 구성에서 어댑터를 지정하지 않습니다.


Answers

database.yml은 다음과 같이 보일 것입니다.

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5
  username: my_username
  password: my_password

development:
  <<: *default
  database: "development_database_name"

test:
  <<: *default
  database: "test_database_name"

production:
  <<: *default
  database: "production_database_name"

development_database_name을 로컬 데이터베이스 이름으로 편집하십시오. my_username과 my_password를 올바른 db 사용자 이름과 암호로 편집하십시오.

Question

내가 heroku를 사용할 때 내 웹 응용 프로그램은 잘 작동하지만 레일즈 (localhost)를 사용할 때이 오류가 발생합니다.

ActiveRecord::AdapterNotSpecified database configuration does not specify adapter

왜 이런거야?

이것은 내 database.yml입니다.

# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5

그리고 이것은 내 보석입니다.

source 'https://rubygems.org'


gem 'pg'

gem 'bootstrap-sass', '~> 3.1.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :production do
  gem 'rails_12factor', '0.0.2'
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]



이 쿼리를 일으키는 명령을 표시하지 않았지만 기호가 아닌 문자열을 전달하면이 문제가 발생할 수 있습니다.

예 :

irb(main):001:0> ActiveRecord::Base.establish_connection("#{Rails.env}")
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter

그러나 심볼을 사용하면 작동합니다.

irb(main):001:0> ActiveRecord::Base.establish_connection("#{Rails.env}".to_sym)
=> #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007f2f484a32a0 #....