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 pool for ActiveRecord::Base" error.
What could it be?
EDIT
The pg gem wasn't working properly. I had to comment it before starting the server and then uncomment it from my GemFile afterwards. I realized that I was using Ruby 2.3 instead of Ruby 2.0 (as intended). I removed ruby 2.3 and set up everything under ruby 2.0 environment. It's now working properly.
I had read somewhere that there were some issues with the 'pg' gem in newer Rails releases, requiring people to use 'gem install pg --pre' instead for installing the gem. I tried that, but then my app was requiring the 'pg' gem in my GemFile and, well, the problem stated above showed up again.
This is how my database.yml file ended up:
default: &default
adapter: postgresql
encoding: unicode
host: localhost
username: -------
password: -------
pool: 5
development:
<<: *default
database: myDbName
If you are experiencing this error from a rake task, chances are you are not running the :environment
task before your task.
Changing:
task :task_name do
end
to:
task task_name: :environment do
end
Should fix the issue.
This issue arises when the server cannot find the corresponding database it depends on to pull data from.
I had same issue from my end, I updated my version of Sqlite3, and it was higher than the version that the current Puma Server version supports.
I simply had to uninstall the Sqlite3 version, and then install the version supported by the current version of Puma Server.
gem uninstall sqlite3
This will uninstall the updated version of Sqlite3, and then you run the code below stating the version supported by your current server.
gem install sqlite3
Or you can as well open your Gemfile, and then include the version for the database that you are using
gem 'sqlite3', '~> 1.3.6'
N/B: The sqlite3 version is the most current version as at the time of writing this answer
And then run
bundle update
to install the version of the database that you specified.
That's all.
I hope this helps.
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.
Check the database.yml
if all settings are ok. If its the first time and you didn't create the database yet use this command to create the database
rake db:create
If the database already exists try reset the db migrations,
rake db:migrate:reset
Hope it'll solve the problem. Go to rails console and try something to check if its working or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With