部署到Herokuy时出现Postgres端口错误
我想部署到Heroku,但我有一个错误:
预编译资产失败。
注意:我已将config.assets.initialize_on_precompile = false
放入我的application.rb中,但它仍然无法正常工作。
`Preparing app for Rails asset pipeline
Running: rake assets:precompile
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_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `initialize'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `new'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `connect'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:542:in `initialize'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:203:in `table_exists?'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:48:in `block in sanity_check'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:46:in `each'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:46:in `sanity_check'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:7:in `configure'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/config/initializers/rolify.rb:1:in `<top (required)>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `each'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `block in <class:Engine>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `each'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `tsort_each_child'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/config/environment.rb:5:in `<top (required)>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'
Tasks: TOP => environment
(See full trace by running task with --trace)
! ! 预编译资产失败。 ! 试图访问不存在的数据库:! https://devcenter.heroku.com/articles/pre-provision-database!
! 推送被拒绝,未能编译Ruby应用程序
谢谢!
一旦你设置了这个代码: config.assets.initialize_on_precompile = false
在推送到heroku
之前,不要忘记进行修改:
git commit -m
git push
送到你的github远程回购
然后git push heroku master
无论何时您对文件进行更改,您都需要先commit
然后push
送到远程仓库,然后push
送到heroku
。 否则,heroku不会选择这个改变。
更新:
Heroku在这里解决了这个问题。 遵循其解决方案
感谢最后一个答案,我有同样的问题,并为我工作。 我只是添加从一般的宝石中删除sqlite3,并将其放入开发组:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor','0.0.2'
end
当然,这是个诀窍
heroku addons:add heroku-postgresql
尝试这个:
1)首先打开你的Gemfile并删除gem'sqlite3 gem 'sqlite3'
,替换如下:
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor','0.0.2'
end
2)然后运行bundle install
3)打开你的config / application.rb并修改如下:
production:
adapter: postgresql
encoding: unicode
database: db/production.postgresql
pool: 5
username: test_postgre
password:
记住git commit并推送它。
4)然后运行heroku addons:add heroku-postgresql
5)现在你可以运行git push heroku master
祝你好运!
链接地址: http://www.djcxy.com/p/48965.html