Error with Postgres Port when deploying to Herokuy

I want to deploy to Heroku but I have an error:

Precompiling assets failed.

NOTE: I've put config.assets.initialize_on_precompile = false in my application.rb but it's still not working.

`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)

! ! Precompiling assets failed. ! Attempted to access a nonexistent database: ! https://devcenter.heroku.com/articles/pre-provision-database !

! Push rejected, failed to compile Ruby app`

Thanks!


once you set this code: config.assets.initialize_on_precompile = false

don't forget to commit the change before pushing to heroku :

git commit -m

git push to your github remote repo

then git push heroku master

anytime you make a change to your file, you need to first commit and then push to your remote repo before pushing to heroku . otherwise, heroku won't pick the change.

UPDATE:

Heroku address this same issue here. follow their solution


Thanks for the last answer, i had the same issue and that worked for me. I would just add to remove sqlite3 from the general gems and put it inside the development group:

group :development, :test do
 gem 'sqlite3'
end

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

And of course, this made the trick

heroku addons:add heroku-postgresql

try this:

1)First open your Gemfile and remove gem 'sqlite3' ,Replace like this:

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

2)Then run bundle install

3)open your config/application.rb and modified like this:

production:
  adapter: postgresql
  encoding: unicode
  database: db/production.postgresql
  pool: 5
  username: test_postgre
  password:

remember git commit and push that.

4) then run heroku addons:add heroku-postgresql

5) now you can run git push heroku master

good luck!

链接地址: http://www.djcxy.com/p/48966.html

上一篇: 在Heroku中使用分支策略的良好Git部署?

下一篇: 部署到Herokuy时出现Postgres端口错误