0

Frnds私はpostgresqldbのために以下のようにdatabase.ymlを編集し、pg gemと関連ライブラリをダウンロードしました。私はそれをグーグルで検索し、そのように編集しました。しかし、サーバーを実行した後、ターミナルウィンドウに以下のエラーが表示されます。 ......これで私を助けてください...

development:
  adapter: postgresql
  encoding: unicode
  database: my db name
  username:  user name
  password: password
  host: host name

test:
  adapter: postgresql
  database: db_pchamara
  database: my db name
  username:  user name
  password: password
  host: host name
  pool: 5


production:
  adapter: postgresql
  database: my db name
  username:  user name
  password: password
  host: host name
  pool: 5

しかし、ターミナルでコマンド「rails server」を実行すると、次のエラーが表示されます。

Started GET "/assets/rails.png" for 127.0.0.1 at 2012-12-05 18:10:51 +0530

ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
  activerecord (3.2.9) lib/active_record/query_cache.rb:67:in `rescue in call'
  activerecord (3.2.9) lib/active_record/query_cache.rb:61:in `call'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `_run__189673354__call__558944823__callbacks'
  activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.9) lib/rails/engine.rb:479:in `call'
  railties (3.2.9) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.6ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (13.3ms)
4

2 に答える 2

1

Gemfileでgem'pg'を設定しましたか?

Gemfileをチェックし、gem sqliteにコメント(または削除)したことを確認し、gempgがリストされていることを確認します

gem 'pg'

その後、bundleコマンドを実行します(アプリケーションが起動する前にロードするライブラリをセットアップします)。

bundle

ファイルGemfile.lockをチェックし、gempgがそこにリストされていることを確認します。

これらすべてが完了したら、postgresqlサーバーに実際にデータベースを作成していることを確認してください。

bundle exec rake db:create

念のため、保留中の移行を実行してください

bundle exec rake db:migrate
于 2012-12-05T13:05:13.507 に答える
0

これが役立つ場合、私のdatabase.ymlは次のとおりです。

development:
  adapter: postgresql
  encoding: utf8
  reconnect: false
  database: kenyu_dev
  pool: 5
  username: kenyu
  password: super_secret_pass
  host: localhost

また、ユーザーを作成し、適切な権限を付与しましたか?でユーザーとしてログインしてみてくださいpsql

于 2012-12-05T13:10:13.783 に答える