Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django character set with MySQL weirdness

Tags:

I'm seeing

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

It looks like some of my variables are UTF8 strings

'name': 'p\xc7\x9d\xca\x87\xc9\x9f\xc4\xb1\xc9\xa5s Badge'

Is this a configuration issue? If so, how can i solve it? I'd like to handle everything in Unicode (I think).

like image 494
Paul Tarjan Avatar asked Jul 02 '09 09:07

Paul Tarjan


2 Answers

You can change the table encoding via the shell:

$ 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

like image 170
webjunkie Avatar answered Oct 17 '22 13:10

webjunkie


It appears your database is defaulted to latin1_swedish_ci, and therefore cannot accept all utf8 characters. You need to change the configuration of the MySQL database tables to use utf8_general_ci. A good blogpost about this (with links to a tool) can be found at MySQL Performance Blog

like image 24
Technical Bard Avatar answered Oct 17 '22 14:10

Technical Bard