2011-03-02 78 views
9

我安裝了所有東西。但是,當我運行「耙分貝:創建」,我得到如下:在Mac OS X上使用Ruby on Rails安裝PostgreSQL

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:寶石名單

我試着用「PG」每個計算器上的另一篇文章替代「的PostgreSQL」,但它導致了這一點:

Ken-Vogts-MacBook:sixmonths ken$ rake db:create 
(in /Users/ken/sixmonths) 

似乎ç哦,對嗎?

沒有。接下來,我嘗試「耙分貝:模式:轉儲」,我得到這個:

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-適配器」。我需要做些什麼來完成這項工作?

的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

貴'Gemfile'有'寶石「pg''的呢? – 2011-03-02 05:04:56

+0

@dmarkow這裏是我的Gemfile:(見下評論) – 2011-03-02 18:19:57

+0

源 'http://rubygems.org' 寶石 '軌道', '3.0.0' #捆綁邊緣軌道,而不是: #寶石 '軌道' ,::git =>'git://github.com/rails/rails。混帳」 寶石 'sqlite3的,紅寶石',:需要=> 'sqlite3的' #寶石 '麒麟' #寶石 'Capistrano的' #寶石 '紅寶石調試' #捆綁了額外的寶石: #寶石 'BJ' #寶石 '引入nokogiri' #寶石 '的sqlite3-紅寶石',:需要=> 'sqlite3的' #寶石 'AWS-S3',:需要=> 'AWS/S3' #捆綁寶石爲當地的環境。確保 #把測試只有寶石本組中,以便它們的發電機 #和耙任務的發展模式可供選擇: #組:發展,:測試你 #寶石「webrat」 #結束 – 2011-03-02 18:22:39

回答

12

的Rails 3只會讓你訪問你在Gemfile指定的寶石,所以即使你把它做一個gem install pg安裝在系統範圍內的寶石,它贏得了」無法找到它。

gem 'pg'加到你的Gemfile,運行bundle install,你應該很好走。

+1

我加了寶石「根據你的指示。工作的適配器是「postgresql」,而不是「pg」,適用於那些瞭解我上面的攻擊嘗試的人。現在開始學習postgresql(我是一個mysql人員)。 – 2011-03-02 23:11:32

+5

是的,即使gem是'pg',你仍然在'database.yml'中使用'postgresql' – 2011-03-03 03:50:57

0

我試了很多事情,我看到的解決方案,在其他地方,但只爲我工作的事情是在Gemfile中與

gem 'pg' 

更換

gem 'sqlite3' 

。我的database.yml看起來和你的一樣。

現在都>rake db:create>rake db:migrate工作。

這是在OSX Snow Leoard,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)