aerijman
aerijman

Reputation: 2762

ActiveRecord::ConnectionNotEstablished (No connection pool with 'primary' found.)

The postgresql table looks like:

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

I am trying to retrieve the data:

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

and I get the error stated in the title from activerecord-5.2.4.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1032:in retrieve_connection'`.

I don't have the most basic understanding of what's going on... Help.

Also, what does 'primary' stand for?

Thank you!

Upvotes: 0

Views: 2046

Answers (1)

Paul Watson
Paul Watson

Reputation: 824

I suspect your config/database.yml is not configured correctly.

In that file you should have something similar to:

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

development:
  <<: *default
  database: database_name_development
...

You want to make sure that database_name_development is the name of the database in your local PostgreSQL instance. Is your database actually called primary as that is what the error seems to be saying.

You show the psql output with the table named MyPreferredGenomeName so whatever database that is in is needed in database.yml.

You can test what database Rails is looking for with:

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

(Do not post any secrets in any replies e.g. db passwords or full connection strings.)

Upvotes: 1

Related Questions