Rails using unkown config file for database connection - ruby-on-rails

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

Related

Configure database with sqlite3 for Rails and postgreSQL for Heroku

I looked for hours on the web but none of my attempts to adapt my database.yml work out. I just started with Rails and the exercise is to use sqlite3 for development, and postgreSQL for production. I am using rvm 2.4.1 and rails 5.3.1.
I added this to my gemfile:
group :production do
gem 'pg'
end
And this is my database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 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
So that does not work out and I get the following error when I try to deploy to heroku:
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 ActiveRecord).
I am assuming I need to somehow let the production part lead to postgreSQL but the manuals on the heruko website and other posts on stackOverflow and elsewhere are not helping me. How can I get it work? I can add :default to the groups, gem 'pg' is in within my Gemfile but then other things like scaffolding produce errors later on. I would really be thankful to get specific help on this as a spend about 12 hours on this single issue already..
first, since you informed in your production using postgresql then you must change setting in database.yml (see production part)
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 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:
adapter: postgresql
encoding: unicode
database: project_name_production
pool: 5
host: localhost
username: your_username
password: your_database_password
and then you can follow this rake command in heroku
second about your gem file, if the problem still persist then you can put out from production environtment and push to heroku, and then do bundle install to install the adapter
GEMFILE
gem 'pg'
here is good for your to read to solve your problem link information for heroku with postgresql

ActiveRecord::ConnectionNotEstablished for new project

I made a wrong choice and now I am sticked at the middle of my project
I used ruby 5.0.0rc1, and while I start my project with rubymine I get "ActiveRecord::ConnectionNotEstablished"
I also get an error message while I type rake db:create :
Gregoires-MacBook-Pro:p1 gregoire$ rake db:create
Rake tasks not supported by 'pg' adapter
Couldn't create database for {"adapter"=>"pg", "pool"=>5, "timeout"=>5000, "database"=>"pg"}
rake aborted!
ActiveRecord::Tasks::DatabaseNotSupported: Rake tasks not supported by 'pg' adapter
my database/yml :
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: 'pg'
pool: 5
timeout: 5000
development:
<<: *default
database: 'pg'
test:
<<: *default
database: 'pg'
production:
<<: *default
database: 'pg'
I am newbie with ror , any help will be appreciated (please detail)
greg
config/database.yml gives Rails the information needed to access the database of your choice.
The adapter name pg is not valid. If you intend to use PostgreSQL, you should set it as postgresql.
And you have to make sure PostgreSQL is installed and running.
A typical database.yml could be like the following:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
timeout: 5000
username: your_username_for_postgresql
password: your_password_for_postgresql
development:
<<: *default
database: your_app_name_development
test:
<<: *default
database: your_app_name_test
production:
<<: *default
database: your_app_name_production
username: your_username_for_postgresql_on_production
password: your_password_for_postgresql_on_production
Thanks for your answers, I had multiple problems :
1/ Postgresql was not properly installed AND running
Fresh install using some comments found here :
https://gist.github.com/lxneng/741932
2/ my database .yml was nos properly configured, I created users with
new access : http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/
What you gave me as advise made me find the way, also a project 'out of the box' was not runable
Thanks for your time and advises
greg

Postgresql with Ruby on Rails

I want to migrate from sqlite3 to postgresql. After doing search I found that I should change my database.yml to somthing like that:
adapter: postgresql
encoding: unicode
database: [insert your dev database name]
pool: 5
username: [insert your user name]
password:
But I don't know what to provide in place of database, username and password. Because i don't remember creating any of them. I just created my rails app and migrations , and thats it.
To configure your rails project with postgres database
do the below steps.
provide your database details in the database.yml file
eg:
development:
username: postgres
database: ur-db-dev
password: pass
encoding: UTF8
adapter: postgresql
timeout: 500
pool: 5
add postgres gem in your Gemfile
gem 'pg'
then,
Do bundle install to install postgres gem
rake db:create to create your database
rake db:migrate to migrate your migration files

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

could not open database

I typed cd generate and then rake db:migrate, but the CMD shows that rake aborted could not open database you can refer to chap2 of the book [Ruby on Rails] OReilly Head First Rails Jan A learner's companion to Ruby on Rails 2009
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development: adapter: sqlite3 database: db/development.sqlite3 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 timeout: 5000
production: adapter: sqlite3 database: db/production.sqlite3 timeout: 5000
Sounds like your database is not properly configured. Make sure that config/database.yml matches the settings for your computer, and that you can log into the database on the host and port specified with the username and password specified.
It might help to see config/database.yml and the details of your database setup.
If your config/database.yml and adapter are configured correctly, try running rake db:create:all before running rake db:migrate

Resources