一切都在本地工作正常,但是当我尝试推送到heroku时我得到了错误:
正在运行:rake assets:precompile
Connecting to database specified by DATABASE_URL rake aborted! could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
/tmp/build_1903c764-07ce-4d06-aa45-6e78dec68af8/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in`initialize'
/tmp/build_1903c764-07ce-4d06-aa45-6e78dec68af8/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `new'
... 等
我怀疑它必须对database.yml做些什么,所以这里是:
development:
adapter: mysql2
encoding: utf8
database: dev-db
pool: 5
timeout: 5000
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
database: test-db
pool: 5
timeout: 5000
socket: /tmp/mysql.sock
production:
adapter: postgresql
encoding: utf8
database: prod-db
pool: 5
timeout: 5000
# socket: /tmp/mysql.sock
答案 0 :(得分:27)
这可能与您在推送到heroku之前未预先配置数据库这一事实有关。至少,我有类似的错误,我通过运行解决了它:
heroku addons:create heroku-postgresql
您可以运行以下命令验证数据库是否已添加到您的应用程序中:
heroku config
您可以在此处阅读有关此问题的所有内容:https://devcenter.heroku.com/articles/pre-provision-database
答案 1 :(得分:5)
见this article。解决方案是设置
config.assets.initialize_on_precompile = false
答案 2 :(得分:1)
我知道这已经解决了,但对于其他看到此问题的人来说,您可能需要推广数据库(如果您创建了新数据库,还原到新数据库或类似数据库):
heroku pg:promote HEROKU_POSTGRESQL_IVORY
(替换IVORY)