gpt4 book ai didi

ruby-on-rails - 将 Postgresql 数据库与 Ruby 应用程序集成

转载 作者:行者123 更新时间:2023-11-29 14:12:20 25 4
gpt4 key购买 nike

我刚刚开始构建我的第一个 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 预构建的,我已经设置了表、主键和外键。我不确定这是否是它拒绝工作的原因。任何帮助将非常感激。谢谢

最佳答案

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

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

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

gem 'pg'

在终端运行 bundle install。

在这里,我向您发送了我的 DB.yml 示例

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

您可能需要将 pg_hba.conf 配置为在您的本地主机上无需密码即可登录。

关于ruby-on-rails - 将 Postgresql 数据库与 Ruby 应用程序集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11660478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com