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

DB をレーキしようとすると、これがエラーになります。

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'

端末で bundle install を実行します。

ここで、私の DB.yml の例をお送りします

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

localhost でパスワードなしでログインするには、pg_hba.conf を構成する必要がある場合があります。

チーズ

于 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 に答える