1. 安装数据库驱动pymsql
$ pip3 install pymysql
2. 安装完毕,打开_init_.py,添加代码:
import pymysql
pymysql.install_as_MySQLdb()
若有报错说什么版本问题的话。
解决方法:在python的MySQL包中,我的环境路径:F:\Project\PythonEnve\***\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. 我是想通过已有数据库生成模型。执行命令
python manage.py inspectdb userphone
报错:
File "F:\Project\PythonEnve\***\lib\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'