92

ソースからインストールpostgresql-9.2.4しましたが、実行するとレールアプリに表示されます:

rake db:create私が得るコマンド:

$ bin/rake db:create RAILS_ENV="test"
PG::Error: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT:  Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "verticals_test" ENCODING = 'unicode'
/home/vagrant/my-project/.gems/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `exec
....
bin/rake:16:in `load'
bin/rake:16:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"my_db", "host"=>"localhost", "pool"=>5, "username"=>"my_user", "password"=>"my_password"}

何か案が?

4

6 に答える 6

46

database.ymlファイルに正しい設定があることを確認してください。template0エラーが示唆するように、を使用する必要があります。

test:
  adapter: postgresql
  encoding: unicode
  database: your_db_name
  template: template0
  host: localhost
  ...
于 2013-05-24T14:15:19.173 に答える
2

同様の問題がありました。私のdatabase.ymlは次のようでした:-

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: chatapp_development

test:
  <<: *default
  database: chatapp_test

production:
  <<: *default
  database: chatapp_production
  username: chatapp
  password: <%= ENV['CHATAPP_DATABASE_PASSWORD'] %>

template: template0 をデフォルト設定に追加しました

default: &default
  adapter: postgresql
  template: template0
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

そしてそれは働いた

于 2017-08-09T10:14:46.803 に答える