I bumped into this error, when I am updating the column (datatype text) on django admin.py
.
unicode error happens only for update
'\\xF0\\x9F\\x98\\xA1' for column 'object_repr' at row 1
This is because of UTF-8 problem,When I use 4byte character it happens.
The text data(it uses 4byte characters) is already stored in mysql database and definition of table is like this below.
show create table tweet_corpus;
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tweet_corpus | CREATE TABLE `tweet_corpus` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` text,
`manual_judge` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2471024 DEFAULT CHARSET=utf8mb4 |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
And connection from django to mysql is utf8mb4
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'corpustest',
'USER': 'root',
'PASSWORD': 'mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
'charset': 'utf8mb4',
}
}
}
my admin.py is like this ,
class CorpusAdmin(admin.ModelAdmin):
list_display = ['text','manual_judge']
search_fields = ['text','manual_judge']
list_editable = ['manual_judge']
def _issues(self,row):
return row.id
Is there any place I need to check???