为什么我的代码和Postgres没有连接 [英] How come my code and postgres are not connecting

查看:64
本文介绍了为什么我的代码和Postgres没有连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to change my database.yml file to postgresql. This is an extension from my previous question Changing sqlite to pg Hope anyone could help

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

I have changed my database.yml file to what my question's answer was

这是我的database.yml文件

this is my database.yml file

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'

这是我的完整记录

推荐答案

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

Make sure you're installed postgresql on your local env and you've started it before opening your web app

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

Remove sqlite gem, and add gem 'pg' to your Gemfile.

对于postgresql数据库配置,以下是我的并且可以正常工作

For postgresql database configuration, below is mine and it works


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'] %>

这篇关于为什么我的代码和Postgres没有连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆