【问题标题】:ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.)ActiveRecord::ConnectionNotEstablished(没有找到“主”的连接池。)
【发布时间】:2021-04-11 20:14:21
【问题描述】:

postgresql 表如下所示:

      id |                  name                   | size |              md5sum
     ----+-----------------------------------------+------+----------------------------------
       1 |         MyPreferredGenomeName           | 1000 | df768fde8e10e15511c41895363bcce6

我正在尝试检索数据:

myData = myClass.find_by name: "MyPreferredGenomeName" # also tried with other columns
# or 
myData = myClass.where name: "MyPreferredGenomeName" 

我从activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1032:in retrieve_connection'`得到标题中所述的错误。

我对正在发生的事情没有最基本的了解......帮助。

另外,“主要”代表什么?

谢谢!

【问题讨论】:

    标签: ruby-on-rails postgresql rails-activerecord


    【解决方案1】:

    我怀疑您的config/database.yml 配置不正确。

    在该文件中,您应该有类似以下内容:

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

    您要确保 database_name_development 是本地 PostgreSQL 实例中的数据库名称。您的数据库实际上是否称为primary,因为这就是错误的意思。

    您使用名为MyPreferredGenomeName 的表显示psql 输出,因此database.yml 中需要其中的任何数据库。

    您可以测试 Rails 正在寻找的数据库:

    rails console
    ActiveRecord::Base.connection.current_database
    => "database_name_development"
    

    (请勿在任何回复中发布任何秘密,例如数据库密码或完整连接字符串。)

    【讨论】:

      猜你喜欢
      • 2015-09-12
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2021-01-01
      • 2021-10-05
      • 2019-07-08
      • 2019-06-07
      • 1970-01-01
      相关资源
      最近更新 更多