[英]How come my code and postgres are not connecting
I am trying to change my database.yml file to postgresql. 我正在尝试将database.yml文件更改为postgresql。 This is an extension from my previous question Changing sqlite to pg Hope anyone could help 这是我上一个问题的扩展, 将sqlite更改为pg希望任何人都可以提供帮助
I have changed my database.yml file to what my question's answer was 我已将database.yml文件更改为我的问题的答案是
this is my database.yml file 这是我的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
this is the exact indentation 这是确切的缩进
i am getting: 我正进入(状态:
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'
that is my full trace 那是我的全部痕迹
Make sure you're installed postgresql on your local env and you've started it before opening your web app 确保在本地环境中安装了postgresql,并且在打开Web应用程序之前已启动它
Remove sqlite
gem, and add gem 'pg'
to your Gemfile. 删除sqlite
gem,然后将gem'pg gem 'pg'
添加到您的Gemfile中。
For postgresql database configuration, below is mine and it works 对于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'] %>
重新插入代码,例如connection: &connection adapter: postgresql host: localhost port: 5432 username: postgres password: postgres pool: 5 timeout: 5000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.