小编Jar*_*ard的帖子

操作'='的非法混合排序(utf8mb4_unicode_ci,EXPLICIT)和(utf8_general_ci,COERCIBLE)

好吧,我放弃了.我有2天这个错误,我需要帮助.

免责声明:我需要帮助改进这个问题,并会尽力描述手头的问题,到目前为止我已经做了什么来解决这个问题,并分享博客文章和我读过的文件解.

问题(也在下文中提到):

所以问题是,为什么从Rails运行而不是从mysql命令行运行时,相同的查询表现不同?具体来说,"(utf8_general_ci,COERCIBLE)"来自哪里?

问题:Autoresponder.find_by(keyword: '')失败并出现以下错误:

ActiveRecord::StatementInvalid: Mysql2::Error: Illegal mix of collations 
(utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) 
for operation '=': 
SELECT  `autoresponders`.* 
FROM `autoresponders`  
WHERE `autoresponders`.`keyword` = '' 
LIMIT 1
Run Code Online (Sandbox Code Playgroud)

Autoresponder 是具有该属性的模型 keyword

我读到我需要指定我的校对.所以我测试了以下代码:

Autoresponder.where('keyword collate utf8mb4_unicode_ci = ?', '')
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

Illegal mix of collations 
(utf8mb4_unicode_ci,EXPLICIT) and (utf8_general_ci,COERCIBLE) 
for operation '=': 
SELECT `autoresponders`.* 
FROM `autoresponders`  
WHERE (keyword collate utf8mb4_unicode_ci = '')
Run Code Online (Sandbox Code Playgroud)

所做的一切都是将整理从IMPLICIT改为EXPLICIT.

我尝试在Sequel Pro中运行查询并且它有效(使用和不使用collat​​e关键字).为清楚起见,这里是查询:

SELECT `autoresponders`.* 
FROM `autoresponders`  
WHERE (keyword collate utf8mb4_unicode_ci = '');

SELECT `autoresponders`.* 
FROM `autoresponders`  
WHERE (keyword …
Run Code Online (Sandbox Code Playgroud)

mysql ruby-on-rails collation utf-8

11
推荐指数
2
解决办法
8683
查看次数

标签 统计

collation ×1

mysql ×1

ruby-on-rails ×1

utf-8 ×1