0

Running rake db:create is not working. Here is the stacktrace:

/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
rake aborted!
LoadError: Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to your Gemfile.)

/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:377:in `block (2 levels) in replace_gem'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:7:in `<top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:29:in `spec'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:101:in `create_database'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:62:in `each'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

Gem::LoadError: pg is not part of the bundle. Add it to your Gemfile.
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/bundler-1.15.2/lib/bundler/rubygems_integration.rb:377:in `block (2 levels) in replace_gem'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:7:in `<top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:29:in `spec'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:101:in `create_database'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:62:in `each'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activerecord-3.2.13/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

Tasks: TOP => db:create
(See full trace by running task with --trace)
2
  • Update all the bundle gems and then try to create the DB. Commented Jul 20, 2017 at 13:34
  • Please post your gemfile Commented Jul 20, 2017 at 13:34

1 Answer 1

3

The error says:

pg is not part of the bundle. Add it to your Gemfile.

To do so simply go to your Rails app directory and open the Gemfile and place the following into it.

Example Config:

Gemfile:
# Use PostgreSQL as the database for Active Record
gem 'pg'
database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: postgres
  password: 
  timeout: 5000

development:
  <<: *default
  database: myawesomeapp_dev

# 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: myawesomeapp_test

production:
  <<: *default
  database: myawesomeapp_prod

After you've added the line, save your file and hit bundle install in your rails app directory to install the required gem.

Also be sure to have a user on your PostgreSQL instance which is allowed to connect and to create new databases. You don't need to create the databases by yourself.

Sign up to request clarification or add additional context in comments.

7 Comments

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"myapp_test", "pool"=>5, "username"=>"myapp", "password"=>nil} now it is giving this error
Do you have a running PostgreSQL instance with the user/role myapp which is granted connect and create?
No then I should create a user/role for my app in postgresql
Yes, just create the user and grant the privileges. Rails will create the required databases for you.
/Users/mounikasmitha/.rvm/gems/ruby-2.4.0/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now myapp already exists myapp already exists -----it is showing this error!!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.