【问题标题】:Rails ActionView::Template::Error: Mysql2::Error: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT)Rails ActionView::Template::Error: Mysql2::Error: 非法混合排序规则 (utf8_unicode_ci,IMPLICIT) 和 (utf8_general_ci,IMPLICIT)
【发布时间】:2017-02-08 18:57:17
【问题描述】:

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

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

ActionView::Template::Error: Mysql2::Error: 排序规则 (utf8_unicode_ci,IMPLICIT) 和 (utf8_general_ci,IMPLICIT) 的非法混合

accepted answer 表示 COLLATE,但我希望有一些特定于 Rails 的示例。

【问题讨论】:

    标签: ruby-on-rails mysql2


    【解决方案1】:

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

    之前:

    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
    

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

    【讨论】:

      猜你喜欢
      • 2010-11-03
      • 2012-07-30
      • 2018-01-19
      • 2016-02-19
      • 2020-04-15
      • 2012-03-01
      • 1970-01-01
      • 2023-03-21
      • 2014-12-04
      相关资源
      最近更新 更多