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'.
Related
My professor said it would be wise to use PostgreSQL instead of SQLite in our project so that it would be easier to deploy to Heroku, but it seems that I didn't set up the database.yml properly.
Here's what I tried to do after I installed the Pg gem. The default database.yml content was:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# 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:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
I decided to change the default adapter "sqlite3" to "postgresql", hence:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
but when I use scaffold I get the error:
Specified 'postgresql' for database adapter but the gem is not loaded. Add 'gem pg' to your Gemfile and ensure its version is at the minimum required by active record
so I'm guessing that I need to put something like gem 'postgresql' in the gemfile. But the problem is I dont know the current version of PostgreSQL I have now so that I can put it on that line.
How do I know the current version of the PostgreSQL? Is this going solve my PostgreSQL setup for my project?
To use Postgres with Ruby on Rails you should follow these steps:
add the pg gem to your Gemfile which is located in the root directory of your application
run bundle install, which will install the gem and set its version and dependencies in your Gemfile.lock
install and configure postgres in your computer
configure the connection uri in config/database.yml by changing
database: db/development.sqlite3
to something like
database: "postgres://username:password#hostname:port/database_name"
In your Gemfile just add pg gem to your production group
group :production do
gem 'pg', '~> 0.19.0'
end
Then run bundle
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
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
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 ?
When I want to deploy my app to heroku (using git push heroku master), it gives me an error and told me to install sqlite3 -v '1.3.6'. So after successfully installing that gem, I tried deploying it again to heroku and it still give me the same error!! However, I've already installed it. And now I can't even run my rails project locally (rails server). May I know what could be the cause of this?
Here's my content in database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# 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
Heroku does not work with SQLite3
Open your Gemfile and replace the line:
gem 'sqlite3'
for
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
I also suggest you to read the heroku instructions: https://devcenter.heroku.com/articles/rails3
Make your gemfile look like this
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3-ruby', :require => 'sqlite3'
end