gpt4 book ai didi

activerecord - 数据库配置没有指定适配器(Sinatra + Heroku + Activerecord)

转载 作者:行者123 更新时间:2023-12-04 04:58:52 29 4
gpt4 key购买 nike

我收到一个错误(在 Sinatra + ActiveRecord Heroku 上)数据库配置没有指定适配器

根据一些研究,这似乎是因为 Heroku 预计在 rackup 期间不使用环境变量。

我从列出数据库 URL 的数据库环境文件中删除了环境变量,但我仍然遇到同样的错误。

编辑:这在一天前也有效,数据库文件未更改,所以我不确定哪里出了问题。

2015-09-01T02:44:40.980448+00:00 app[web.1]: I, [2015-09-01T02:44:40.980313 #3]  INFO -- : Refreshing Gem list
2015-09-01T02:44:41.459544+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:171:in `spec': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
2015-09-01T02:44:41.459548+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
2015-09-01T02:44:41.459550+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-activerecord-2.0.8/lib/sinatra/activerecord.rb:43:in `database='
2015-09-01T02:44:41.459552+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1216:in `set'
2015-09-01T02:44:41.459554+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-activerecord-2.0.8/lib/sinatra/activerecord.rb:35:in `database_file='
2015-09-01T02:44:41.459555+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1216:in `set'
2015-09-01T02:44:41.459556+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-activerecord-2.0.8/lib/sinatra/activerecord.rb:19:in `registered'
2015-09-01T02:44:41.459560+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1399:in `block in register'
2015-09-01T02:44:41.459562+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1397:in `each'
2015-09-01T02:44:41.459563+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1397:in `register'
2015-09-01T02:44:41.459565+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1977:in `register'
2015-09-01T02:44:41.459566+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:2038:in `register'
2015-09-01T02:44:41.459567+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-activerecord-2.0.8/lib/sinatra/activerecord.rb:54:in `<module:Sinatra>'
2015-09-01T02:44:41.459569+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/sinatra-activerecord-2.0.8/lib/sinatra/activerecord.rb:10:in `<top (required)>'
2015-09-01T02:44:41.459571+00:00 app[web.1]: from /app/app.rb:2:in `require'
2015-09-01T02:44:41.459575+00:00 app[web.1]: from /app/app.rb:2:in `<top (required)>'
2015-09-01T02:44:41.459576+00:00 app[web.1]: from config.ru:2:in `require'
2015-09-01T02:44:41.459578+00:00 app[web.1]: from config.ru:2:in `block in <main>'
2015-09-01T02:44:41.459587+00:00 app[web.1]: from config.ru:1:in `<main>'
2015-09-01T02:44:41.459589+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/unicorn-4.9.0/lib/unicorn.rb:48:in `eval'
2015-09-01T02:44:41.459590+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/unicorn-4.9.0/lib/unicorn.rb:48:in `block in builder'
2015-09-01T02:44:41.459581+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
2015-09-01T02:44:41.459600+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/bin/unicorn:23:in `load'
2015-09-01T02:44:41.459582+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
2015-09-01T02:44:41.459601+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/bin/unicorn:23:in `<main>'
2015-09-01T02:44:41.459584+00:00 app[web.1]: from config.ru:1:in `new'
2015-09-01T02:44:41.459593+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:768:in `build_app!'
2015-09-01T02:44:41.459595+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:137:in `start'
2015-09-01T02:44:41.459598+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/unicorn-4.9.0/bin/unicorn:126:in `<top (required)>'
2015-09-01T02:44:41.459592+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:768:in `call'
2015-09-01T02:44:42.358161+00:00 heroku[web.1]: State changed from starting to crashed
2015-09-01T02:44:42.351187+00:00 heroku[web.1]: Process exited with status 1

这是数据库配置文件。

#The environment variable DATABASE_URL should be in the following format:
# => postgres://{user}:{password}@{host}:{port}/path




configure :development, :production do
db = URI.parse("REMOVED ACTUAL DB URL")


ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)

#adding development REDIS config
ENV["REDISTOGO_URL"] = "REMOVED ACTUAL DB URL"

end



configure :development do
db = URI.parse('postgres://postgres:PASS@localhost/development')

#adding development REDIS config
ENV["REDISTOGO_URL"] = "REMOVED ACTUAL REDIS URL"

ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
end





#set up the test database
configure :test do
db = URI.parse('postgres://postgres:PASS@localhost/test')


#adding development REDIS config
ENV["REDISTOGO_URL"] = "REMOVED ACTUAL DB URL"

ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
end

这是 database.yml 文件:

development:
adapter: postgresql
database: development
username: <%= ENV['PG_USER'] %>
password: <%= ENV['PG_PASS'] %>
host: localhost

test:
adapter: postgresql
database: test
username: <%= ENV['PG_USER'] %>
password: <%= ENV['PG_PASS'] %>
host: localhost

编辑 2:看起来损坏来自四次提交中的一次。下面看看其中一个发生了什么变化:(编辑 3:https://www.dropbox.com/s/dnw41av20uoxf8w/GitHub%20Diff2.pdf?)

最佳答案

我今天遇到了同样的问题,并联系了 Heroku 支持寻求帮助。

他们告诉我他们的 Ruby 构建包最近发生了变化,请看这里:https://devcenter.heroku.com/changelog-items/709

我更新了我的 database.yml 文件以反射(reflect)更改,并为生产引用了 DATABASE_URL,我的应用程序正在再次部署。

production:
url: <%= ENV['DATABASE_URL'] %>

关于activerecord - 数据库配置没有指定适配器(Sinatra + Heroku + Activerecord),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32322937/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com