我正在得到一个Incorrect string value (Exception Value: Incorrect string value: '\xEA\xB0\x95\xED\x95\x98...' for column 'object_repr' at row 1)
尝试在 Django 和 MySQL 中保存 unicode 字符串(韩语)时出错。我遇到的第一个问题是数据库表中每一列的“字符串值不正确”错误。但是,我通过更改列排序规则和整体数据库字符集解决了这个问题。
我收到的新错误与unicodemodels.py 中的 (self) 方法。My models.py 如下:
from django.db import models
# Create your models here.
class User(models.Model):
full_name = models.CharField(max_length=60)
email = models.EmailField(unique=True)
password = models.CharField(max_length=128)
birthday = models.DateField(null=True, blank=True)
gender = models.PositiveIntegerField(null=True, blank=True)
location = models.CharField(max_length=60, null=True, blank=True)
captcha = models.CharField(max_length=60, null=True, blank=True)
register_date = models.DateTimeField()
lastLogin_date = models.DateTimeField(null=True)
num_logins = models.PositiveIntegerField()
def __unicode__(self):
return self.full_name
错误发生时__unicode__
函数尝试输出 utf8 字符...
有谁知道如何修复这个错误?
在 MySQL 控制台中执行
ALTER DATABASE django_db CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE django_admin_log MODIFY object_repr VARCHAR(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL;
对我来说这有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)