Rails: No connection pool for ActiveRecord::Base

后端 未结 9 1020
梦毁少年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.

    0 讨论(0)
  • 2020-12-29 08:17

    For PostgreSQL your database.yml file should look something like that:

    default: &default
      adapter: postgresql
      encoding: unicode
      # For details on connection pooling, see rails configuration guide
      # http://guides.rubyonrails.org/configuring.html#database-pooling
      pool: 5
    
    development:
      <<: *default
      database: your_db_name
    

    Also make sure that you have the gem installed: in your Gemfile:

    gem 'pg'
    

    Finally, restart your server.

    Hope that helps

    Edit: I almost forgot, make sure you have your PostgresSQL running, check this link for download and setup.

    0 讨论(0)
  • 2020-12-29 08:17

    I've encountered the same problem when I try to access the Model before creating the DataBase.

    Make sure you run rake db:migrate at least once.

    If you already run migration then check the Database as mentioned in previous answers.

    0 讨论(0)
提交回复
热议问题