django使用mysql的坑
坑1.django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?
解决方法 先安装pymysql pip install pymysql 在你的项目目录下__init__.py,添加下面一段代码
import pymysql
pymysql.install_as_MySQLdb()

坑2.django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
解决方法 找到Python安装路径下的Python36\Lib\site-packages\django\db\backends\mysql\base.py文件 将文件中的如下代码注释掉: if version < (1, 3, 3): raise ImproperlyConfigured(“mysqlclient 1.3.3 or newer is required; you have %s” % Database._version 
坑3. File “/data/env/django_env/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’
解决方法: Python36\lib\site-packages\django\db\backends\mysql\operations.py”, line 146, in last_executed_query query = query.decode(errors=‘replace’) if query is not None: 修改为以下代码:
try:
query = query.encode(errors='replace')
except:
query = query.decode(errors='replace')

|