2017-07-26 15 views
0

PostgreSQLでRails 5をデプロイして、Herokuでアプリを無料にする。これはdatabase.ymlから私の設定です:Heroku、PosgreSQL with Rails 5でマイグレーションを実行するとエラーが発生する

production: 
    adapter: postgresql 
    username: root 
    password: 
    database: example 

私はheroku run rake db:migrateを実行すると、私はこのエラーを参照してください。

rake aborted! PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

私はdatabase.ymlに次の行を追加する場合:

host: localhost 

と再び移行を実行しますこのエラーが表示されます:

rake aborted! PG::ConnectionBad: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

修正方法?

+0

あなたは印刷することができます'heroku config --app your_app_name'コマンドの出力? –

+0

LANG:EN_US.UTF-8 RACK_ENV:生産 RAILS_ENV:生産 RAILS_LOG_TO_STDOUT: RAILS_SERVE_STATIC_FILESを有効にします。https:// githubの 'rails_12factor'は一切のRails 5.チェックドキュメンテーションのために必要とされる – gdfgdfg

答えて

2

データベースがあなたのアプリケーションのために提供されていないように、あなたは1を追加する必要がありそうです:

heroku addons:create heroku-postgresql 

あなたは、データベースを実行して、アプリケーションに追加されたことを確認することができます

heroku config --app your_app_name 
0

、Gemfileで

  1. $ heroku login

  2. をシリアル順序でいくつかの手順に従ってください、あなたのRailsプロジェクトにPGの宝石を追加します。変更:Gemfileで

    gem 'sqlite3', group: :development
    gem 'pg', '0.18.1', group: :production

  3. gem sqlite

    、rails_12factorの宝石を追加::

    gem 'rails_12factor', group: :production

  4. $ bundle install

  5. config/database.ymlがpostgresqlアダプタを使用していることを確認してください。変更:

    production:
    <<: *default
    database: db/production.sqlite3

    production:
    <<: *default
    adapter: postgresql
    database: db/production.sqlite3

  6. $ heroku run rake db:migrate
  7. $ git push heroku master
  8. $ heroku create$ git add .
    $ git commit -m "Heroku config"
  9. は、私はそれが働いていた願っています。

これは正しく実行されます。

+1

HERE yyyyyyyyyyyyyyyyyyyyyyy KEY: SECRET_KEY_BASEを有効になっていません。 com/heroku/rails_12factor – gdfgdfg

+0

はい、私のミス – djmayank

関連する問題