ActiveRecord :: StatementInvalid-PG :: CharacterNotInRepertoire:错误:编码“ UTF8”的字节序列无效

问题描述

该问题的现有解决方案无济于事。

路轨: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表中的users数据类型

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

解决方法

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...