【问题标题】:django-models database collations problems: declare a field that supports unicode?django-models 数据库排序规则问题:声明一个支持 unicode 的字段?
【发布时间】:2012-12-25 17:32:03
【问题描述】:

我遇到了这个问题。当我无法将 unicode 字符串分配给 models.CharField 时。

DatabaseError: (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='")

我找到了this solution,但它似乎对我不起作用。数据库返回此错误:

Error Code: 1025. Error on rename of './test_database/#sql-272e_1ba' to './test_database/[MY_TABLE_NAME]' (errno: 150)

此外,所有这些解决方案似乎只能在创建表后才能工作,或者修改 python manage.py sql APP_NAME 输出并手动创建表。

有没有办法从最初在 python 代码中声明 django 模型时解决这个问题,所以 manage.py syncdb 只会生成正确的表?

【问题讨论】:

    标签: django django-models collation django-database


    【解决方案1】:

    这似乎是您的数据库配置的问题,而不是 Django。我的猜测是,无论您使用什么数据库,它都配置为将 latin1_swidish_ci 用于新表。您可以hook syncdb 并在那里更改表,但我认为您最好直接修复您的数据库配置。

    【讨论】:

      猜你喜欢
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 2011-11-14
      • 2020-05-28
      • 1970-01-01
      • 2016-09-29
      相关资源
      最近更新 更多