15 | | 2. In django.core.db.backends.mysql.DatabaseWrapper in method cursor() |
16 | | When you doing |
17 | | {{{ |
18 | | self.connection = Database.connect(**kwargs) |
19 | | cursor = self.connection.cursor() |
20 | | if self.connection.get_server_info() >= '4.1': |
21 | | cursor.execute("SET NAMES 'utf8'") |
22 | | }}} |
23 | | After 'set names ..' the charset of connection was changed. |
24 | | But self.connection.charset property (property of MySQLdb.connection) was not changed. It is always 'Latin1' |
25 | | So, when i pass u"unicode national characters" into database, MySQLdb tryed to convert it into Latin1 and exception raises |
26 | | |
27 | | To fix it, i must set .charset propery manually: |
28 | | {{{ |
29 | | ... |
30 | | self.connection = Database.connect(**kwargs) |
31 | | self.connection.charset = 'utf8' |
32 | | cursor = self.connection.cursor() |
33 | | if self.connection.get_server_info() >= '4.1': |
34 | | cursor.execute("SET NAMES 'utf8'") |
35 | | ... |
36 | | }}} |
37 | | |