Rails: No connection pool for ActiveRecord::Base

后端 未结 9 1084
梦毁少年i
梦毁少年i 2020-12-29 07:27

I\'m trying to use rails 4.2.6 to develop an app. I\'m trying to use postgres for database. Server starts fine but when I try loading a page it throws this \"No connection p

9条回答
  •  感动是毒
    2020-12-29 08:16

    In my case, the config/database.yml was taking variables from the environment:

    # ...
    test:
      <<: *default
      database: <%= ENV.fetch("DB_NAME") %>_test
      username: <%= ENV.fetch("DB_USER") %>
      password: <%= ENV.fetch("DB_PASS") %>
    # ...
    

    The error was coming when the new terminal window where I was running the bundle exec rails spec did not have those variables initialized.

    Doing,

    $ export DB_NAME=mydb
    $ export DB_USER=myuser
    $ export DB_PASS=mypass
    $ bundle exec rails spec
    

    fixed the issue.

提交回复
热议问题