Cod*_*oza 3 mysql django utf-8
我Incorrect string value (Exception Value: Incorrect string value: '\xEA\xB0\x95\xED\x95\x98...' for column 'object_repr' at row 1)在尝试在Django和MySQL中保存unicode字符串(韩文)时遇到错误.我遇到的第一个问题是数据库表中每列的"字符串值不正确"错误.但是,我通过更改列排序规则和整个数据库字符集来解决这个问题.
我得到的新错误与models.py中的unicode(self)方法有关.我的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
Run Code Online (Sandbox Code Playgroud)
当__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;
Run Code Online (Sandbox Code Playgroud)
对我来说它有帮助.
| 归档时间: |
|
| 查看次数: |
3050 次 |
| 最近记录: |