版权声明:多多交流。 https://blog.csdn.net/qq_42776455/article/details/84945017
Django2.1更改数据库类型为mysql报错解决
Django默认是使用python自带的splite3数据库(小型轻量级关系数据库),现在改为mysql,settings.py文件如下:
运行报错:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
找不到mysql程序,但我明明已经安装了。参考这个:https://blog.csdn.net/qq_42776455/article/details/82959857
不管是java还是python,还是什么语言连接数据库都需要先加载数据库驱动程序,所以就明白了这里要安装一个python-mysql的驱动pip install pymysql
注意要在虚拟环境里安装。
然后在__init__.py文件中添加:
import pymysql
# 当成mysqldb一样使用,当然也可以不写这句,就按照pymysql的方式
pymysql.install_as_MySQLdb()
python 3.X中:PyMYSQL取代了MySQLdb。
个人觉得这两者的用法就是名字变了,看个人选择。
写好之后就正常使用了。
如果还是失败,重启下pycharm,右下角会有一个提示,点击之后安装driver
点击 Test Connection:
连接成功。
如果接着报错信息如下:
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1"))
哈哈哈,那么可以告诉你了,Django2.1版本后不再支持mysql5.5了。