【问题标题】:ActiveRecord::StatementInvalid - PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8"ActiveRecord::StatementInvalid - PG::CharacterNotInRepertoire:错误:编码“UTF8”的字节序列无效
【发布时间】:2020-08-13 02:49:54
【问题描述】:

这个问题的现有解决方案没有帮助。

导轨:5.2 红宝石:2.4.1 pg:0.18

This is the query from the rails log: 
INSERT INTO "users" ("first_name") VALUES ('\xC3\r\x04\t\x03\x02qlF\xA4\.....')

first_name 值使用active_record-pgcrypto gem 加密

first_namestring 表中的string 数据类型

在 pgAdmin 中复制粘贴查询效果很好。但是应用程序抛出错误。

【问题讨论】:

    标签: ruby-on-rails postgresql pg


    【解决方案1】:

    pgcrypto install documentation 中所述,加密数据应使用:binary 列。否则 Rails 和 Postgres 会将其解释为 UTF-8 字符,并且某些字节组合不是有效的 UTF-8 字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-13
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      相关资源
      最近更新 更多