让人头痛的django编码问题。。
平台:windows2003+python2.5+django0.91+mysql5.0
使用django提供的models功能,将数据存入mysql数据,只要含有中文就提示(1406, "Data too long for
column 'title' at row 1"),title刚刚两个字,列我设置的varchar(30)。奇怪的是无论通过python的控制
台还是GUI连mysql插入数据都是正常的,只是通过django就返回这个错误。该设编码的地方都设置了,python和django、mysql
编码从utf-8到zh-cn。。。都报错。
查看debug的信息,插入语句为:
INSERT INTO `msgboard_message`
(`title`,`nickname`,`email`,`website`,`imgface`,`imgemot`,`content`,`ipaddress`,`adddate`)
VALUES ('\xe4\xb8\xad','sdf','sadf','','<img src=/images/
face01.gif>','<img src=/images/emot/em01.gif>','asfd\xe4\xb8\xad
\xe6\x96\x87','127.0.0.1','2008-04-27 12:37:00')
以下是部分debug的信息:
D:\Python25\Lib\site-packages\MySQLdb\cursors.py in execute
else: self.messages.append((TypeError,
m)) self.errorhandler(self, TypeError, m)
except: exc, value, tb = exc_info() del
tb self.messages.append((exc, value))
self.errorhandler(self, exc, value) ... self._executed =
query if not self._defer_warnings: self._warning_check()
return r def executemany(self, query, args):▼ Local vars
Variable Value
ListType <type 'list'>
TupleType <type 'tuple'>
args ['\xe4\xb8\xad', 'sdf', 'sadf', '', '<img src=/images/
face01.gif>', '<img src=/images/emot/em01.gif>', 'asfd\xe4\xb8\xad
\xe6\x96\x87', '127.0.0.1', '2008-04-27 12:37:00']
charset 'utf8'
db <weakproxy at 01464CC0 to Connection at 012A4500>
exc <class '_mysql_exceptions.DataError'>
exc_info <built-in function exc_info>
query "INSERT INTO `msgboard_message`
(`title`,`nickname`,`email`,`website`,`imgface`,`imgemot`,`content`,`ipaddress`,`adddate`)
VALUES ('\xe4\xb8\xad','sdf','sadf','','<img src=/images/
face01.gif>','<img src=/images/emot/em01.gif>','asfd\xe4\xb8\xad
\xe6\x96\x87','127.0.0.1','2008-04-27 12:37:00')"
self <MySQLdb.cursors.Cursor object at 0x014666F0>
value DataError(1406, "Data too long for column 'title' at row 1")
D:\Python25\Lib\site-packages\MySQLdb\connections.py in
defaulterrorhandler
error = errorclass, errorvalue if cursor:
cursor.messages.append(error) else:
connection.messages.append(error) del cursor del connection
raise errorclass, errorvalue ...class
Connection(_mysql.connection): """MySQL Database Connection
Object"""▼ Local vars
Variable Value
error (<class '_mysql_exceptions.DataError'>, DataError(1406, "Data
too long for column 'title' at row 1"))
errorclass <class '_mysql_exceptions.DataError'>
errorvalue DataError(1406, "Data too long for column 'title' at row
1")