MySQL の奇妙な Django 文字セット 質問する

MySQL の奇妙な Django 文字セット 質問する

私は見ている

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

いくつかの変数はUTF8文字列のようです

'名前': 'p\xc7\x9d\xca\x87\xc9\x9f\xc4\xb1\xc9\xa5s バッジ'

これは設定の問題でしょうか? もしそうなら、どうすれば解決できますか? すべてを Unicode で処理したいです (そう思います)。

ベストアンサー1

シェル経由でテーブルのエンコーディングを変更できます。

$ manage.py shell
>>> from django.db import connection
>>> cursor = connection.cursor()
>>> cursor.execute('SHOW TABLES')
>>> results=[]
>>> for row in cursor.fetchall(): results.append(row)
>>> for row in results: cursor.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8 COLLATE     utf8_general_ci;' % (row[0]))

https://mayan.readthedocs.org/en/v0.13/faq/index.html

おすすめ記事