为什么我的代码和Postgres没有连接

时间:2019-08-23 01:14:16

标签: ruby-on-rails ruby database postgresql sqlite

我正在尝试将database.yml文件更改为postgresql。 这是我上一个问题Changing sqlite to pg的扩展 希望有人能帮忙

我已将database.yml文件更改为我的问题的答案

这是我的database.yml文件

connection: &connection
adapter: postgresql
host: localhost
port: 5432
username: postgres
password: postgres
pool: 5
timeout: 5000
min_messages: warning

development:
  <<: *connection
  database: development_db_name
test:
  <<: *connection
 database: test_db_name

production:
  <<: *connection
  database: production_db_name

这是确切的缩进

我正在:

ActiveRecord::ConnectionNotEstalblished
No connection pool with 'primary' found



vendor/cache/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1013:in `retrieve_connection'
vendor/cache/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
vendor/cache/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
vendor/cache/gems/activerecord-5.2.3/lib/active_record/migration.rb:554:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
vendor/cache/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:98:in `run_callbacks'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:14:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
vendor/cache/gems/web-console-3.7.0/lib/web_console/middleware.rb:135:in `call_app'
vendor/cache/gems/web-console-3.7.0/lib/web_console/middleware.rb:30:in `block in call'
vendor/cache/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch'
vendor/cache/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
vendor/cache/gems/railties-5.2.3/lib/rails/rack/logger.rb:38:in `call_app'
vendor/cache/gems/railties-5.2.3/lib/rails/rack/logger.rb:26:in `block in call'
vendor/cache/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb:71:in `block in tagged'
vendor/cache/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb:28:in `tagged'
vendor/cache/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb:71:in `tagged'
vendor/cache/gems/railties-5.2.3/lib/rails/rack/logger.rb:26:in `call'
vendor/cache/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/request_id.rb:27:in `call'
vendor/cache/gems/rack-2.0.7/lib/rack/method_override.rb:22:in `call'
vendor/cache/gems/rack-2.0.7/lib/rack/runtime.rb:22:in `call'
vendor/cache/gems/activesupport-5.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:14:in `call'
vendor/cache/gems/actionpack-5.2.3/lib/action_dispatch/middleware/static.rb:127:in `call'
vendor/cache/gems/rack-2.0.7/lib/rack/sendfile.rb:111:in `call'
vendor/cache/gems/railties-5.2.3/lib/rails/engine.rb:524:in `call'
vendor/cache/gems/puma-3.12.1/lib/puma/configuration.rb:227:in `call'
vendor/cache/gems/puma-3.12.1/lib/puma/server.rb:660:in `handle_request'
vendor/cache/gems/puma-3.12.1/lib/puma/server.rb:474:in `process_client'
vendor/cache/gems/puma-3.12.1/lib/puma/server.rb:334:in `block in run'
vendor/cache/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'

那是我的全部踪迹

2 个答案:

答案 0 :(得分:0)

请确保您在本地环境中安装了postgresql,并且已在打开Web应用程序之前启动了它

删除sqlite个gem,并将gem 'pg'添加到您的Gemfile中。

对于postgresql数据库配置,以下是我的并且可以使用


default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: my_app_development

test:
  <<: *default
  database: my_app_test

production:
  <<: *default
  database: my_app_production
  username: freelancer
  password: <%= ENV['FREELANCER_DATABASE_PASSWORD'] %>

答案 1 :(得分:0)

connection: &connection adapter: postgresql host: localhost port: 5432 username: postgres password: postgres pool: 5 timeout: 5000