Django admin 保存unicode报错 <MySQL“incorrect string alue” error > 解决办法
来源:互联网 发布:刘欢和孙楠 知乎 编辑:程序博客网 时间:2024/06/05 18:19
如题,原因是创建数据库和表的时候 默认字符集设置的问题,修改即可。
下面是批量修改数据库所有表的列的 默认字符集 Python 脚本
#! /usr/bin/env pythonimport MySQLdbhost='localhost'password='your passwd'user='your user name'dbname='your database naem'db=MySQLdb.connect(host=host,user=user,passwd=password,db=dbname)cursor=db.cursor()cursor.execute("ALTER DATABASE `%s` CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'" % dbname)sql = "SELECT DISTINCT(table_name) FROM information_schema.columns WHERE table_schema = '%s'" % dbnamecursor.execute(sql)results=cursor.fetchall()for row in results:#print row[0]sql="ALTER TABLE %s convert to character set DEFAULT COLLATE DEFAULT " % (row[0])cursor.execute(sql)db.close()python 运行即可。
MySQL 版本为 5.5,其他版本没有试。
打开MySQL 可以查看修改后的表的字符集
mysql> SELECT T.table_name, T.table_collation, CCSA.character_set_name FROM information_schema.`TABLES` T, -> information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA -> WHERE CCSA.collation_name = T.table_collation -> AND T.table_schema = "databasename";+----------------------------+-----------------+--------------------+| table_name | table_collation | character_set_name |+----------------------------+-----------------+--------------------+| auth_group_permissions | utf8_unicode_ci | utf8 || auth_permission | utf8_unicode_ci | utf8 || auth_user | utf8_unicode_ci | utf8 || auth_user_groups | utf8_unicode_ci | utf8 || auth_user_user_permissions | utf8_unicode_ci | utf8 || table_name1 | utf8_unicode_ci | utf8 || table_name2 | utf8_unicode_ci | utf8 || table_name3 | utf8_unicode_ci | utf8 || table_name4 | utf8_unicode_ci | utf8 || django_admin_log | utf8_unicode_ci | utf8 || django_content_type | utf8_unicode_ci | utf8 || django_session | utf8_unicode_ci | utf8 |+----------------------------+-----------------+--------------------+14 rows in set (0.03 sec)
0 0
- Django admin 保存unicode报错 <MySQL“incorrect string alue” error > 解决办法
- django admin 中文报错Incorrect string value解决方案
- django 保存中文到mysql 报错django.db.utils.DatabaseError: Incorrect string value: '\xE5\xBE\x88\xE7\x81\xB5
- 解决MySql 报错:ERROR 1366 (HY000): Incorrect string value....
- Mysql 字符串保存报错Incorrect string value: '...' for column 'DepartmentName' at row 1
- MySQL表中存Emoji报错Error 1366: Incorrect string value的解决方法
- Django-admin录入中文错误:Incorrect string value
- Django admin界面出现 Incorrect string value 错误
- (linux下windows下一样)mysql如何插入中文,解决插入中文报错,ERROR 1366 (HY000):Incorrect string value
- MySql中插入中文报错:incorrect string value
- incorrect string value MySql中文字符报错
- mysql插入数据报错 Incorrect string value for column
- Django报错403 Forbidden. CSRF token missing or incorrect的解决办法
- Django报错403 Forbidden. CSRF token missing or incorrect的解决办法
- Django Admin 输入中文报错
- django admin录入数据报错
- django admin 报错没有发现 table
- mysql从5.6版本导入5.5报错:Error Code : 1293 Incorrect table definition
- 网络爬虫的基本原理
- Log4net创建日志及简单扩展
- wince 6.0 回调函数的理解(转)
- LINQ
- iOS学习之iOS沙盒(sandbox)机制和文件操作之NSFileManager(三)
- Django admin 保存unicode报错 <MySQL“incorrect string alue” error > 解决办法
- 漫谈php引用计数
- 进程和线程的知识总结
- 使用Powermock和Mockito测试静态方法
- 毕业10年经历【转载】
- ActionSupport.getText()方法
- 数值计算一阶常微分方程求解实现
- Time33哈希算法
- Struts2的文件下载