2012-07-26 32 views
0

我剛開始構建我的第一個Ruby on Rails應用程序,爲了讓我在heroku上託管它,我已在應用程序中更改了我的數據庫設置。我通過更改我的應用程序中的database.yml文件來做到這一點。這就是我現在所擁有的。將Postgresql數據庫與Ruby應用程序集成

# SQLite version 3.x 
# gem install sqlite3-ruby (not necessary on OS X Leopard) 
development: 
    adapter:postgresql 
    encoding:unicode 
    database:dezirus_dev 
    pool:5 
    host:localhost 
    username:postgres 
    password: 
    port:5432 
# timeout: 5000 

# 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: 
    adapter:postgresql 
    encoding:unicode 
    database:dezirus_test 
    pool:5 
    username:postgres 
    password: 
    host:localhost 
    port:5432 

production: 
    adapter:postgresql 
    encoding:unicode 
    database:dezirus 
    pool:5 
    username:postgres 
    password: 
    host:localhost 
    port:5432 

當我嘗試耙DB時,這是我得到的錯誤。

[email protected] ~/rails-projects/dezirus 
$ rake db:migrate --trace 
rake aborted! 
no such file to load -- pg 
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require' 
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require' 
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `each' 
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `require' 
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `each' 
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `require' 
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.22/lib/bundler.rb:122:in `require' 
/home/RAHMAN/rails-projects/dezirus/config/application.rb:7 
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' 
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' 
/home/RAHMAN/rails-projects/dezirus/Rakefile:4 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/usr/lib/ruby/gems/1.8/gems/rake-0.9.2.2/bin/rake:33 
/usr/bin/rake:23:in `load' 
/usr/bin/rake:23 

請注意,數據庫是使用postgreSQL預建的,我已經有了我的表,主鍵和外鍵集。我不確定是否這也是它拒絕工作的原因。任何幫助將非常感激。由於

+0

是否安裝了皮克的寶石? posgresql實際上在運行嗎?你需要兩個。 – thisfeller 2012-07-26 00:19:04

回答

3

首先在計算機中安裝PG,http://www.postgresql.org/download/

嘗試用PGAdmin3打開它(它與數據庫管理員),並創建一個新的BD

未來在創業板文件中添加此

gem 'pg' 

在終端運行軟件包安裝。

,在這裏我給你一個例子我DB.yml

development: 
    adapter: postgresql 
    encoding: unicode 
    database: billy 
    pool: 5 
    username: postgres 
    password: 

你可能需要配置的pg_hba.conf,而無需在本地主機密碼登錄。

cheerz

+0

我的機器上安裝了PGIII,現在它正在運行。我現在會更改寶石文件,看看它是否有幫助。請在哪裏找到pg_nba文件? – 2012-07-26 00:38:35

+0

你在哪個操作系統中運行? – 2012-07-26 00:46:12

+0

我正在運行Windows 7 32位....在Cygwin中運行Ruby – 2012-07-26 00:49:18

1

添加寶石「PG」你的寶石文件並運行

bundle install 

然後去這裏http://www.postgresql.org/download/和數據庫安裝到你的機器,以本地運行你的應用程序。

+0

這是我最初做的,但現在當我嘗試捆綁安裝時,出現錯誤,說明我的PostgreSQL版本太舊或過時。對我來說根本沒有意義。 – 2012-07-26 16:10:38

0

嘿傢伙我終於找到了我遇到的不同問題的解決方案。事實證明,cygwin pg gem不支持我的PostgreSQL版本,我使用了ruby安裝程序,並且安裝時沒有退縮。然後我用這行代碼添加到boot.rb文件

require 'yaml' 
YAML::ENGINE.yamler = 'syck' 

YML文件也需要看起來像這樣。

development: 
    adapter: postgresql 
    encoding: unicode 
    database: dezirus_dev 
    pool: 5 
    username: postgres 
    password: 
# 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: 
    adapter: postgresql 
    encoding: unicode 
    database: dezirus_test 
    username: postgres 
    password: 
production: 
    adapter: postgresql 
    encoding: unicode 
    database: dezirus 
    username: sudo 
    password: ******* 

我然後跑耙分貝:遷移命令,瞧:)

相關問題