Django无法在DB中保存文本值

时间:2016-02-03 12:54:06

标签: django python-2.7 django-models

我正在通过我的Django应用程序中的IMAP阅读电子邮件内容。

当我尝试将一些已解析的内容分配给对象并执行.save()时,它返回:

ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

当我打印变量类型时:。 DB中的字段定义为CharField。我也尝试过TextField,但结果是一样的。

我如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

如果您的邮件文本在mail_text中,请执行以下操作:

mail_text = unicode(mail_text)