I am upgrading Rails 4.1 app to use Ruby 2.2. During upgrade it turned out that the app used old version of pg gem (0.12) and gem was not installing using Ruby 2.2. So I tried to use newer version of pg gem (0.17.1). Now I sometimes get following error when a new user is created in the system:
我正在升级Rails 4.1应用程序以使用Ruby 2.2。在升级期间,结果发现该应用程序使用旧版本的pg gem(0.12)并且gem未使用Ruby 2.2进行安装。所以我尝试使用更新版本的pg gem(0.17.1)。现在,有时在系统中创建新用户时会出现以下错误:
PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8"
PG :: CharacterNotInRepertoire:错误:编码“UTF8”的无效字节序列
Are there any known issues with Ruby 2.2 and Postgres?
Ruby 2.2和Postgres有任何已知问题吗?
Looks like application is configured to use unicode: config.encoding = "utf-8"
is set in application.rb and encoding: unicode
is in database.yml
看起来应用程序配置为使用unicode:config.encoding =“utf-8”在application.rb中设置并且编码:unicode在database.yml中
SQL statement:
INSERT INTO "users" (
"confirmation_sent_at",
"confirmation_token",
"created_at",
"email",
"encrypted_password",
"first_name",
"last_name",
"updated_at")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING "id"
2 个解决方案
#1
5
Looks like this is a known issue with "pg" gem: https://bitbucket.org/ged/ruby-pg/issue/197/ruby-220-byte-encoding-issue
看起来这是“pg”gem的一个已知问题:https://bitbucket.org/ged/ruby-pg/issue/197/ruby-220-byte-encoding-issue
It should be fixed in 0.18 pre-release
它应该在0.18预发布中修复
#2
5
There is definitely some kind of bug in Ruby 2.2.0 re UTF-8 encoding with Postgres. I upgraded a previously bug free Rails 4.1.5 app from Ruby 2.1.5 to Ruby 2.2.0 and started getting these errors "PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding UTF8" on user input email fields in both development and in a staging environment on Heroku. Downgrading to Ruby 2.1.5 with no other changes fixed the issue completely.
在使用Postgres的Ruby 2.2.0重新UTF-8编码中肯定存在某种错误。我将以前无错误的Rails 4.1.5应用程序从Ruby 2.1.5升级到Ruby 2.2.0并开始在开发和用户输入电子邮件字段中获取这些错误“PG :: CharacterNotInRepertoire:ERROR:用于编码UTF8的无效字节序列”在Heroku的临时环境中。降级到Ruby 2.1.5而没有其他更改完全解决了这个问题。
update:
Beat to the punch on this update but the bug does not lie in Ruby but rather the pg gem: https://github.com/ged/ruby-pg/pull/5
打败这个更新,但错误不在于Ruby,而是pg gem:https://github.com/ged/ruby-pg/pull/5
#1
5
Looks like this is a known issue with "pg" gem: https://bitbucket.org/ged/ruby-pg/issue/197/ruby-220-byte-encoding-issue
看起来这是“pg”gem的一个已知问题:https://bitbucket.org/ged/ruby-pg/issue/197/ruby-220-byte-encoding-issue
It should be fixed in 0.18 pre-release
它应该在0.18预发布中修复
#2
5
There is definitely some kind of bug in Ruby 2.2.0 re UTF-8 encoding with Postgres. I upgraded a previously bug free Rails 4.1.5 app from Ruby 2.1.5 to Ruby 2.2.0 and started getting these errors "PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding UTF8" on user input email fields in both development and in a staging environment on Heroku. Downgrading to Ruby 2.1.5 with no other changes fixed the issue completely.
在使用Postgres的Ruby 2.2.0重新UTF-8编码中肯定存在某种错误。我将以前无错误的Rails 4.1.5应用程序从Ruby 2.1.5升级到Ruby 2.2.0并开始在开发和用户输入电子邮件字段中获取这些错误“PG :: CharacterNotInRepertoire:ERROR:用于编码UTF8的无效字节序列”在Heroku的临时环境中。降级到Ruby 2.1.5而没有其他更改完全解决了这个问题。
update:
Beat to the punch on this update but the bug does not lie in Ruby but rather the pg gem: https://github.com/ged/ruby-pg/pull/5
打败这个更新,但错误不在于Ruby,而是pg gem:https://github.com/ged/ruby-pg/pull/5