Rails 6 on Heroku: ActiveRecord::AdapterNotSpecified: 数据库配置没有指定适配器
Rails 6 on Heroku: ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
我们的 Rails 应用刚刚升级到 Rails 6.0,但部署到 Heroku 失败:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <top (required)> at /tmp/build_b9759d496c72c1085bb8441e3c2159fb/config/application.rb:7)
rake aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
/tmp/build_b9759d496c72c1085bb8441e3c2159fb/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `spec'
config/database.yml:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
username: <%= ENV['POSTGRESQL_USER'] %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
url: <%= ENV['DATABASE_URL'] %>
使用版本:
- rails (6.0.0)
- Ruby (2.6.5)
有人知道如何解决这个问题吗?
问题已通过在database.yml中添加'adapter'到'production'解决。当我们的项目在 Rails 4 和 5 时,这不是必需的。
production:
adapter: postgresql
一个更好的解决方案就是使用 ENV["DATABASE_URL"]
指定连接详细信息并将默认段保持为实际的最小默认值:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default
这避免了潜在的开发者战争。您可以使用 DotEnv 为每个环境加载不同的环境变量。或者,您可以将另一个哈希添加到 database.yml 并合并它:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
local_settings: &local_settings
# will raise an exception on nil instead of failing silently
username: <%= ENV.fetch('POSTGRESQL_USER') %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
<<: *local_settings
database: OurApplication_development
test:
<<: *default
<<: *local_settings
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default
我们的 Rails 应用刚刚升级到 Rails 6.0,但部署到 Heroku 失败:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <top (required)> at /tmp/build_b9759d496c72c1085bb8441e3c2159fb/config/application.rb:7)
rake aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
/tmp/build_b9759d496c72c1085bb8441e3c2159fb/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `spec'
config/database.yml:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
username: <%= ENV['POSTGRESQL_USER'] %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
url: <%= ENV['DATABASE_URL'] %>
使用版本:
- rails (6.0.0)
- Ruby (2.6.5)
有人知道如何解决这个问题吗?
问题已通过在database.yml中添加'adapter'到'production'解决。当我们的项目在 Rails 4 和 5 时,这不是必需的。
production:
adapter: postgresql
一个更好的解决方案就是使用 ENV["DATABASE_URL"]
指定连接详细信息并将默认段保持为实际的最小默认值:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default
这避免了潜在的开发者战争。您可以使用 DotEnv 为每个环境加载不同的环境变量。或者,您可以将另一个哈希添加到 database.yml 并合并它:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
local_settings: &local_settings
# will raise an exception on nil instead of failing silently
username: <%= ENV.fetch('POSTGRESQL_USER') %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
<<: *local_settings
database: OurApplication_development
test:
<<: *default
<<: *local_settings
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default