This is moved over from #1355:
2. In django.core.db.backends.mysql.DatabaseWrapper? in method cursor()
When you doing
self.connection = Database.connect(**kwargs)
cursor = self.connection.cursor()
if self.connection.get_server_info() >= '4.1':
cursor.execute("SET NAMES 'utf8'")
After 'set names ..' the charset of connection was changed.
But self.connection.charset property (property of MySQLdb.connection) was not changed. It is always 'Latin1'
So, when i pass u"unicode national characters" into database, MySQLdb tryed to convert it into Latin1 and exception raises
To fix it, i must set .charset propery manually:
...
self.connection = Database.connect(**kwargs)
self.connection.charset = 'utf8'
cursor = self.connection.cursor()
if self.connection.get_server_info() >= '4.1':
cursor.execute("SET NAMES 'utf8'")
...