1. __init_.py文件添加如下配置:
# coding=utf-8 import pymysql pymysql.install_as_MySQLdb()
2.执行迁移文件
出错
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11.None
将出错文件中
C:\Users\dell\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\django\db\backends\base\base.py
中的
if version < (1, 3, 3):
raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
注释掉
3.继续执行仍然出错
File "/home/pyvip/.virtualenvs/myblog/lib/python3.6/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
将decode改为encode就可以了

本文详细记录了解决Django框架在使用MySQL数据库时遇到的迁移错误过程,包括__init_.py配置修改、pymysql版本升级及文件中decode方法的更正。
3124

被折叠的 条评论
为什么被折叠?



