PG ::错误:错误:新编码(UTF8)不兼容 [英] PG::Error: ERROR: new encoding (UTF8) is incompatible

查看:49
本文介绍了PG ::错误:错误:新编码(UTF8)不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从源代码安装了 postgresql-9.2.4 ,现在在执行时在Rails应用程序中安装了

I have installed postgresql-9.2.4 from the source, now in rails app when I execute:

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"}

有什么想法吗?

推荐答案

好,下面的步骤解决了问题:

Ok, below steps resolved the problem:


  1. 首先,我们需要删除template1。不能删除模板,因此我们首先对其进行修改,使其成为一个普通数据库:

  1. First, we need to drop template1. Templates can’t be dropped, so we first modify it so t’s an ordinary database:

UPDATE pg_database SET datistemplate = FALSE WHERE datname ='template1 ';

现在我们可以将其删除:

Now we can drop it:

DROP DATABASE template1;

现在是时候从template0创建数据库了,使用新的默认编码:

Now its time to create database from template0, with a new default encoding:

使用模板创建数据库template1 =模板0编码='UNICODE';

现在修改template1,以使其实际上是模板:

Now modify template1 so it’s actually a template:

UPDATE pg_database SET datistemplate = TRUE WHERE datname ='template1';

现在切换到template1并真空冻结模板:

Now switch to template1 and VACUUM FREEZE the template:

\c template1

真空冻结;

问题应解决。

这篇关于PG ::错误:错误:新编码(UTF8)不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆