我安装了所有东西。但是当我运行“rake db:create”时,我得到以下内容:
Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)
rake aborted!
no such file to load -- pg
这是我的database.yml:
development:
adapter: postgresql
encoding: unicode
database: sixmonths_development
pool: 5
username: postgres
password: xxxxxxxx
test:
adapter: postgresql
encoding: unicode
database: sixmonths_test
pool: 5
username: sixmonths
password: xxxxxxxx
production:
adapter: postgresql
encoding: unicode
database: sixmonths_production
pool: 5
username: sixmonths
password: xxxxxxxx
我可以看到运行时安装了pg:gem list
我尝试在stackoverflow上的另一篇帖子中用“pg”替换“postgresql”,但结果是:
Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)
看起来很酷,对吧?
不。接下来,我尝试“rake db:schema:dump”,我得到了这个:
Ken-Vogts-MacBook:sixmonths ken$ rake db:schema:dump
(in /Users/ken/sixmonths)
rake aborted!
Please install the pg adapter: `gem install activerecord-pg-adapter` (no such file to load -- active_record/connection_adapters/pg_adapter)
当然没有“activerecord-pg-adapter”。我需要做些什么来完成这项工作?
Gemfile内容:
source 'rubygems.org'
gem 'rails', '3.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'unicorn'
# gem 'capistrano'
# gem 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
答案 0 :(得分:12)
Rails 3只允许您访问您在Gemfile
中指定的宝石,因此即使您通过执行gem install pg
将其安装在系统范围的宝石中,它也无法访问找到它。
将gem 'pg'
添加到Gemfile
,然后运行bundle install
,您就应该好了。
答案 1 :(得分:0)
我尝试了许多其他地方的解决方案,但对我来说唯一有用的就是替换
gem 'sqlite3'
与
gem 'pg'
Gemfile中的。我的database.yml看起来和你的一样。
现在,>rake db:create
和>rake db:migrate
都有效。
这是在OSX Snow Lepoard,Rails 3.0.7,Postgres 9.0。
输出来自:
gem list --local
是
pg (0.11.0)
polyglot (0.3.1)
postgres-pr (0.6.3)
rack (1.2.2, 1.0.1)
rack-mount (0.7.2, 0.7.1, 0.6.14)
rack-test (0.6.0, 0.5.7)
rails (3.0.7, 3.0.5, 2.3.5, 2.2.2, 1.2.6)