简体   繁体   中英

Rake db:create is not working

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM