Django

Code

Ticket #2896 (closed: duplicate)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: lakin@evolvs.com Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

creation.py.diff (2.0 kB) - added by lakin@evolvs.com on 10/10/06 13:59:54.
Patch for db/backends/mysql/creation.py to set column character encodings

Change History

10/10/06 13:59:54 changed by lakin@evolvs.com

  • attachment creation.py.diff added.

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

10/10/06 14:00:56 changed by lakin@evolvs.com

  • component changed from Admin interface to Database wrapper.

Sorry, changing to the appropriate component.

12/15/06 16:18:02 changed by adrian

  • status changed from new to closed.
  • resolution set to duplicate.

Duplicate of #952.

01/28/07 03:03:04 changed by Michael Radziej <mir@noris.de>

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


Add/Change #2896 (Django creates MySQL tables with the default server encoding, but uses utf8 to query them.)




Change Properties
Action