我刚从头开始使用Rails 4应用程序,打算使用Postgres。我去了并将database.yml文件更改为以下内容:
development:
adapter: postgresql
encoding: unicode
database: personalapi_dev
pool: 5
username: nickoneill
password:
host: localhost
# 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: &test
adapter: postgresql
encoding: unicode
database: personalapi_test
pool: 5
username: nickoneill
password:
host: localhost
然而,当我运行rake db:create
时,它给了我以下错误:
uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PG
/Users/nickoneill/.rvm/gems/ruby-2.0.0-p247@personalapi/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:562:in `active?'
/Users/nickoneill/.rvm/gems/ruby-2.0.0-p247@personalapi/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:360:in `verify!'
/Users/nickoneill/.rvm/gems/ruby-2.0.0-p247@personalapi/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:458:in `block in checkout_and_verify'
/Users/nickoneill/.rvm/gems/ruby-2.0.0-p247@personalapi/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__1536634998624253346__checkout__callbacks'
/Users/nickoneill/.rvm/gems/ruby-2.0.0-p247@personalapi/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks'
我尝试过升级Postgres宝石,确保Postgres正在运行等等,但不确定为什么它不起作用。我的计算机上有其他rails应用程序(包括Rails 4)运行得很好,但这个新的无法运行。有什么想法吗?
更新
这是我的宝石文件:
source 'https://rubygems.org'
ruby "2.0.0"
# gem 'bootstrap-sass', '~> 2.3.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
gem 'addressable'
#
# Error handling
#
gem "sentry-raven" #, :git => "https://github.com/getsentry/raven-ruby.git"
#
# Sidekiq gems
#
gem 'sidekiq' , '2.5.4'
gem 'redis' , '~> 3.0'
gem 'unicorn' , '~> 4.5'
# For sidekiq interface
#gem 'sinatra', require: false
gem 'slim'
gem 'sinatra', '>= 1.3.0', :require => nil
# json parsing
gem 'oj' , '2.0.1'
# templates
gem 'haml'
# file storage
# gem "paperclip", "~> 3.1"
# gem 'aws-sdk', '1.8.0'
# Use postgres as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :development , :test do
gem "better_errors"
gem 'fakeweb'
gem 'rspec-rails', '2.12.2'
gem 'shoulda-matchers'
gem 'guard-rspec'
end
group :test do
#gem "cucumber-rails", ">= 1.3.0"
gem 'database_cleaner'
gem 'factory_girl_rails' , '~> 4.0'
gem 'capybara'
gem 'guard-spork'
gem 'spork'
gem "launchy"
gem 'rb-fsevent', '~> 0.9.1'
gem 'faker'
gem 'annotate'
gem 'simplecov'
gem 'guard-rspec'
gem 'growl'
gem 'rb-fsevent', '~> 0.9.1'
end
答案 0 :(得分:7)
根据我将Gemfile更新为gem'pg'的经验,'0.15.1'解决了这个问题。