I am trying to keep comments from an iPhone application, which, at the moment, may most likely include emoticons. No matter what I do, I can not save emoticons in the MySQL database ... Permanent Unicode errors.
- Python 2.6.5
- Django 1.2.1
- MySQL database (installed in utf8 character set for tables and rows)
- Saving data in the VARCHAR field (255)
I get the following message:
Incorrect string value: '\xF0\x9F\x97\xBC \xF0...' for column 'body' at row 1
The line I pass to the database is:
test_txt = u"Emoji - \U0001f5fc \U0001f60c \U0001f47b ...".encode('utf-8')
Update . Here's the model I'm using:
class ItemComment(db.Model):
item = db.ForeignKey(Item)
user = db.ForeignKey(Profile)
body = db.CharField(max_length=255, blank=True, null=True)
active = db.BooleanField(default=True)
date_added = db.DateTimeField(auto_now_add=True)
def __unicode__(self):
return "%s" % (self.item)
It is strange if I try to pass this to the field that I created in MySQL and not in Django models.py, it works fine. But as soon as I register a field in Django models, it dies. Is there a way to keep them, maybe?
.
...
2. UPDATE ( U0001f5fc)
UPDATE 'table' SET 'body' = '🗼', WHERE 'table'.'id' = 1 ; args=(u'\U0001f5fc')
, :
force_unicode(smart_str(value), encoding='utf-8', strings_only=False, errors='ignore')
:
_mysql_exceptions.Warning: Incorrect string value: '\xF0\x9F\x97\xBC' for column 'body' at row 1
!!!
,