我已经从源代码安装了 postgresql-9.2.4
,现在当我执行时在 rails app 中:
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"}
有什么想法吗?
最佳答案
好的,下面的步骤解决了问题:
首先,我们需要删除 template1。模板不能掉,所以我们先修改成普通数据库:
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
现在我们可以放下它了:
DROP DATABASE template1;
现在是时候使用新的默认编码从模板 0 创建数据库了:
创建数据库 template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
现在修改 template1,使其成为一个模板:
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
现在切换到模板 1 并对模板进行 VACUUM FREEZE:
\c template1
真空卡住;
问题应该得到解决。
关于ruby-on-rails - PG::错误:错误:新编码(UTF8)不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16736891/