Rails ActionView :: Template ::错误:Mysql2 ::错误:非法混合排序规则(utf8_unicode_ci,IMPLICIT)和(utf8_general_ci,IMPLICIT)

时间:2017-02-08 18:57:17

标签: ruby-on-rails mysql2

注意:通用SQL答案为Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

这个问题特定于rails / active-record,当你有:

  

ActionView :: Template ::错误:Mysql2 ::错误:非法混合排序(utf8_unicode_ci,IMPLICIT)和(utf8_general_ci,IMPLICIT)

accepted answerCOLLATE说,但我希望提供一些特定于rails的示例。

1 个答案:

答案 0 :(得分:0)

我解决了自己的问题并希望记录

在:

Membership.joins(person: :account).where(foo: :bar)

它显示我有一些整理不匹配,需要更新。

后:

Membership
.joins('INNER JOIN `people` ON `people`.`id` = `memberships`.`person_id`')
.joins('INNER JOIN `accounts` ON `accounts`.`person_id` COLLATE utf8_general_ci = `people`.`id` COLLATE utf8_general_ci')

更具体地说,您在列名后添加COLLATE <UTF8_BLAH>

而不是:

joins accounts on person_id = people.id

使用:

joins accounts on person_id COLLATE utf8_general_ci = people.id COLLATE utf8_general_ci

您还可以通过修复所有表和整个数据库的排序规则来解决此问题。