2

我刚从头开始了一个 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 gem、确保 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
4

1 回答 1

7

根据我将 Gemfile 更新为 gem 'pg' 的经验,'0.15.1' 解决了这个问题。

于 2013-07-16T20:27:17.647 回答