0

PostgreSQL を使い始めようとしていますが、いくつか問題があります。

開発用のデータベースを作成しましたが、動作しています。私はすでにテーブルを作成し、いくつかのオブジェクトを追加しました。この投稿に従ってデータベースを作成しました - http://blog.deliciousrobots.com/2011/12/13/get-postgres-working-on-ubuntu-or-linux-mint/

これがコードです。test_databaseを作成するために実行したものです

denmed@denmed:~/projects/internet_shop$ sudo -u postgres createdb -O denys    internet_shop_test
denmed@denmed:~/projects/internet_shop$ psql -d internet_shop_test -U denys -WPassword for user denys: 
denmed@denmed:~/projects/internet_shop$ psql -d internet_shop_test -U denys -W
 Password for user denys: 
 psql (9.1.7)
 Type "help" for help.
 internet_shop_test=> 

これは、データベースを作成し、それを操作できるかどうかを意味しますか?

次に、別のコンソール(別のコンソールでテストデータベースにログインしたとき)コマンドを実行します

 rake test

このエラーが発生します(カットします):

   Errors running test:units! #<ActiveRecord::StatementInvalid: PG::Error: ERROR:      
database "internet_shop_test" is being accessed by other users
DETAIL:  There are 1 other session(s) using the database.
 : DROP DATABASE IF EXISTS "internet_shop_test">
 Errors running test:functionals! #<RuntimeError: Command failed with status (1): [ruby 
-I"lib:test" -I"/home/denmed/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.0.3/lib" "/home    
/denmed/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" 
"test/functional/**/*_test.rb" ]>

わかりました、データベースにアクセスしていることがわかります。次に、ログインしたテスト db ターミナルを閉じて、rake テストを再度実行すると、次のようになります。

  PG::Error: ERROR:  permission denied to create database
  ...
 Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", 
"database"=>"internet_shop_test", "pool"=>5, "username"=>"denys", 
"password"=>"********"}
 ...
PG::Error: FATAL:  database "internet_shop_test" does not exist

開発およびテスト データベース用の database.yml は次のとおりです。

 development:
  adapter: postgresql
  encoding: unicode
  database: internet_shop_development
  pool: 5
  username: denys 
  password: ********

test:
  adapter: postgresql
  encoding: unicode
  database: internet_shop_test
  pool: 5
  username: denys 
  password: ********

私が間違っていることは何ですか?

4

1 に答える 1

1

ユーザー「denys」には、データベースを作成する権限がありません。エラーはかなり明確で、

Railsに別の(スーパーユーザー)アカウントを使用してデータベースを作成するように指示できるかどうか、またはデータベースの作成手順をスキップできるかどうかはわかりません。

ああ、psql の "-W" フラグも必要ありません。パスワードが必要な場合はパスワードを要求されます。

于 2013-01-11T09:32:36.950 に答える