0

我刚刚开始构建我的第一个 Ruby on Rails 应用程序,为了将它托管在 heroku 上,我更改了我的应用程序中的数据库设置。我通过更改应用程序中的 database.yml 文件来做到这一点。这就是我现在所拥有的。

# 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

当我尝试耙数据库时,这是我得到的错误。

RAHMAN@IMLDEV1-LT ~/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 预先构建的,我已经设置了表、主键和外键。我不确定这是否是它拒绝工作的原因。任何帮助将非常感激。谢谢

4

3 回答 3

3

首先在你的电脑上安装PG,http://www.postgresql.org/download/

尝试用PGAdmin3(自带的DB管理员)打开,新建一个BD

接下来在你的 gem 文件中添加这个

gem 'pg'

在终端运行捆绑安装。

在这里我给你发一个我的 DB.yml 的例子

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

您可能需要将 pg_hba.conf 配置为在您的 localhost 中无需密码即可登录。

欢呼

于 2012-07-26T00:23:32.353 回答
1

将 gem 'pg' 添加到您的 gem 文件并运行

bundle install

然后去这里http://www.postgresql.org/download/并将数据库安装到您的机器上,以便在本地运行您的应用程序。

于 2012-07-26T00:24:53.073 回答
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: *******

然后我运行了 rake db:migrate 命令,瞧 :)

于 2012-07-26T21:27:19.137 回答