扫码关注官方订阅号
为什么我在django自带的admin管理站点上,修改admin账户属性的时候,不论写入中文还是英文或者什么都不做,就点击一下保存并继续都会出现 column 'change_messsage' 类的错误?
mysql的my.ini配置文件的数据库默认编码是utf8
报错信息如下:
看起来像是数据库编码与表内编码及字段编码没有统一所导致的。
看着像数据库编码问题,可以试一下这个脚本
import MySQLdb host = "localhost" passwd = "" user = "root" dbname = "django" db = MySQLdb.connect(host=host, user=user, passwd=passwd, 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'" % dbname cursor.execute(sql) results = cursor.fetchall() for row in results: sql = "ALTER TABLE `%s` convert to character set DEFAULT COLLATE DEFAULT" % (row[0]) cursor.execute(sql) db.close()
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
看起来像是数据库编码与表内编码及字段编码没有统一所导致的。
看着像数据库编码问题,可以试一下这个脚本