gem 'pg' can't be loaded only for rails application - ruby-on-rails

I am using pg gem pg-0.17.1-x86-mingw32. It is working fine when i am connecting it from my ruby codes.But when i am trying to connect it via rails apps, it gives me an error::
"Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile."
I am gettigng this error at the time of executing:: "rake db:migrate"
after changing the database.yml
My yml looks like::
development:
adapter: postgresql
database: postgres
host: localhost
user: postgres
password: postgre90
pool: 5
timeout: 5000
I am using::
Rails -4.0.4
Ruby -1.9.3
Please help.. I am a newbie in ruby on rails

Related

Ruby on Rails - could not load postgres adapter

Building a rails app on heroku (locally). Following their tutorials for rails, and installing postgres locally.
When ever I run the server or generate a migration I get the following err:
LoadError (Could not load 'active_record/connection_adapters/posgtres_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.):
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: myapp_development
username: Name
password: secret
host: localhost
Gem file has: gem 'rails' '4.2.0', and gem 'pg' installed
my machine's OS: Windows 64x
Any and all help appreciated.
Doubtful this is the same issue you are having but, posting these details in case it gives a lead. I'm using Windows 10
I had the same error message. To troubleshoot, I tried to do a reinstall of pg with 'gem install pg' but a file was locked.
Found I had a process still using one of the PG files and shut down the process, deleted the entire pg directory found at C:\Ruby200-x64\lib\ruby\gems\2.0.0\gems\pg-0.18.3-x64-mingw32
Reran 'gem install pg' rake db:setup, rake db:create, rake db:migrate and the error was gone.

Gem::LoadError: when trying to deploy on Heroku - Rails 4

I am trying to deploy an app (just a simple app from a Rails tutorial) to heroku but it keeps giving me the same error message. I use the command:
git push heroku master
It starts well, and then suddenly appears this error:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.
I did bundle install already, everything went smooth there.
Here is my Gemfile:
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
Maybe something I am missing something on databse.yml file?
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
By the way, I don't know if it helps, but I am using Rails 4.0.4, Ruby 2.1.1 and the version of SQLite which comes already installed on Mac, which is 3.7.13
Kirti is right in saying that Heroku does not support sqlite as adapter,
do the following
in the Gemfile:
group :production, :staging do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
in database.yml
production:
adapter: postgresql
database: name_of_your_db
pool: 5
timeout: 5000
SQLite is not intended as a production grade database. Instead Heroku provides production grade PostgreSQL databases as a service.
Read the details SQLite on Heroku

Migrating sqlite3 to postgres in rails app

I have read several posts and watched the railscast on migrating from sqlite3 to pg and all of them seem to have conflicting settings and I have not seen anyone run into the error I'm getting. I have data locally that i do NOT care about. If it gets destroyed that's fine.
Here is what I have done.
Changed database.yml from this:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
To this:
development:
adapter: postgresql
database: app_name_database
pool: 5
timeout: 5000
One thing I did notice about this file and some of the examples is that I do not have encoding, username, or password. Is this necessary?
I updated my gem file from this:
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
To this:
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'pg'
end
Following the instructions - the railscast says to rake db:create:all. However, when I run this I get the following error in console:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Any ideas on what I'm doing incorrectly? Are there rake tasks that need to be done before this?
Thanks
Have you started the Postgresql database ? This is how I start mine - pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start ?

Rails using unkown config file for database connection

I have a weird problem.
I have set my database.yml file to use sqlite3 for all three (production, test, dev) databases
I create a new rails project with all defaults.
I fire up rail server using WEBrick
I get "ActiveRecord::ConnectionNotEstablished" error
I try $rake db:create
I get the following error:
specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile.
I install pg and postgres server and I get
fe_sendauth: no password supplied Error on the webpage
I try $rake db:create again on the console and get
fe_sendauth: no password supplied (which I know is a postgres password error)
It seems that Rails is choosing a different database adapter than in my database.yml file.
I don't know where it could be. It even seems to be looking for a specific database that I used in some previous project. Therefore Rails must be looking at someother config file.
Can someone help.
Add sqlite3 gem to your Gemfile:
gem 'sqlite3'
and set sqlite3 as adapter in your database.yml:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

Unable to connect to PostgreSQL when using SQLite?

The error I get is:
Could not load 'active_record/connection_adapters/postgresql_adapter'. Make sure that the adapter in config/database.yml is valid.
Here's my database.yml:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
production:
adapter: postgresql
user: test-app
encoding: unicode
And my Gemfile:
# Use sqlite3 as the database for Active Record
gem 'sqlite3', :group => :development
group :production do
# For Heroku
gem 'rails_12factor'
gem 'pg'
end
This identical setup works fine with another app, but for some reason refuses to here. Why is it even looking for PostgreSQL in development?
I figured out what the problem was.
I am using the gem dotenv to load my Heroku ENV vars from the .env file into Rails, one of which is a Heroku Postgres URL in the variable ENV['DATABASE_URL'] that was messing with Rails in development.
I removed it and Rails started working properly again.
In the database.yml file, the adapter in production should be 'postgresql' not 'pg'.

Resources