3

Django 中 "Data truncated for column xxx" 解决方法

 2 years ago
source link: https://blogread.cn/it/article/1688?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
您现在的位置首页 --> MySQL --> Django 中 "Data truncated for column xxx" 解决方法

Django 中 "Data truncated for column xxx" 解决方法

浏览:3906次  出处信息

今天在把django开发的系统从开发环境搬到外网的时候,发现凡是中文写入Mysql的时候,都会报错:

Data truncation: Data truncated for column xxx

网上搜了一下,排除了字段本身长度不够,剩下只能是因为mysql的默认编码不是utf-8导致,于是请教了数据组的同事,有两个命令可以修改Mysql 库或者表的编码:

修改库的编码:

alter database dbname CHARACTER SET = utf8;

修改表的编码:

alter table tablename CONVERT TO CHARACTER SET utf8;

之后一切OK。

在次仅作记录。

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK