Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#2896 closed defect (duplicate)

Django creates MySQL tables with the default server encoding, but uses utf8 to query them.

Reported by: lakin@… Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Django creates MySQL tables with the default server encoding, but uses utf8 to query them. I'm using a legacy MySQL 4.1 database, not my choice (shared hosting). Because it had a lot of legacy-data, the default encoding for the server, their databases and the tables is latin1. Django uses a SET NAMES 'utf8' when connecting to the server. But Django does not set the Table or Column encodings to utf8. Rather, it lets MySQL choose. The combination of latin1 column encodings and a connection encoding of utf8 causes the following error:

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

Django should allow for different database encodings, through a settings variable: #952 and #2810. The default can be utf8. More importantly, the mysql driver backend should use this setting for column and database encodings. (see attached patch which is incomplete, but a start).

Attachments (1)

creation.py.diff (2.0 KB) - added by lakin@… 9 years ago.
Patch for db/backends/mysql/creation.py to set column character encodings

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by lakin@…

Patch for db/backends/mysql/creation.py to set column character encodings

comment:1 Changed 9 years ago by lakin@…

  • Component changed from Admin interface to Database wrapper

Sorry, changing to the appropriate component.

comment:2 Changed 9 years ago by adrian

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #952.

comment:3 Changed 8 years ago by Michael Radziej <mir@…>

Hi,

I'm trying to figure out what happens in a number of encoding related tickets. Can you please report the mysql database version you were using at that time? It looks like this is really a bug in specific mysql database versions, see http://dev.mysql.com/doc/refman/4.1/en/charset-collation-charset.html

Note: See TracTickets for help on using tickets.
Back to Top