我刚刚开始构建我的第一个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和我已经有我的表,主键和外键集。我不知道是否可能这就是为什么它拒绝工作或没有。任何帮助将不胜感激。谢谢
3条答案
按热度按时间voase2hg1#
首先在计算机http://www.postgresql.org/download/中安装PG
尝试使用PGAdmin3(它附带的数据库管理员)打开它,并创建一个新的BD
接下来在你的gem文件中添加
在终端运行捆绑安装。
这里我给你一个DB.yml的例子
您可能需要在本地主机中配置pg_hba.conf,使其无需密码即可登录。
z9ju0rcb2#
将gem 'pg'添加到gem文件并运行
然后转到http://www.postgresql.org/download/并将数据库安装到您的计算机上,以便在本地运行您的应用程序。
noj0wjuj3#
嘿伙计们我终于找到了一个解决不同问题的方法。原来cygwin pg gem不支持我的PostgreSQL版本,我用了ruby安装程序,它安装毫不退缩。然后我用不得不添加这行代码到 Boot .rb文件
YML文件也需要看起来像这样。
然后我运行rake db:migrate命令,瞧:)