到达数据库迁移的时候, 出现了错误
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
安装pymysql包
pip install pymysql
然后在与想settings.py 同一文件夹的_init_.py中增加
import pymysql
pymysql.install_as_MySQLdb()
增加完成了之后又出现了错误
File "/Users/mac/.virtualenvs/django-sPhxDNwQ/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 36, in <module> raise ImproperlyConfigured(‘mysqlclient 1.3.13 or newer is required; you have %s.‘ % Database.__version__) django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
方案是去Django的包中改代码
路径是:
/Users/mac/.virtualenvs/django-sPhxDNwQ/lib/python3.7/site-packages/django/db/backends/mysql/base.py
我的是虚拟环境,个人找自己mysql的安装包文件base.py
把这行
if version < (1, 3, 13):
raise ImproperlyConfigured(
‘mysqlclient 1.3.13 or newer is required; you have %s.‘
% Database.__version__
)
改成这样, 全部注释:
#if version < (1, 3, 13):
# raise ImproperlyConfigured(
# ‘mysqlclient 1.3.13 or newer is required; you have %s.‘
# % Database.__version__
#)
然后在改另一个文件
路径是: /Users/mac/.virtualenvs/django-sPhxDNwQ/lib/python3.7/site-packages/django/db/backends/mysql/operations.py
把这行
query = query.decode(errors=‘replace‘)
改成
query = query.encode(errors=‘replace‘)