Django将数据库切换为Mysql及mysqlclient 1.3.13 or newer is required; you have 0.9.2报错解决方案
1.安装pymysql数据库驱动:
pip install pymysql
python3不支持MySQLdb,所以用pymysql代替
2.配置Django中的DATABASE
在settings.py中找到DATABASE
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’, #数据库引擎
‘NAME’: ‘dj_experiment_db’, #数据库名
‘USER’: ‘root’, #账户名
‘PASSWORD’: ‘password’, #密码
‘HOST’: ‘localhost’, #主机
‘PORT’: ‘3306’, #端口
}
}
接着在项目下的_init_.py添加如下代码
import pymysql
pymysql.install_as_MySQLdb()
然后在settings.py文件中设置TIME_ZONE为自己的时区
TIME_ZONE = ‘Asia/Shanghai’
最后执行数据库迁移命令
python manage.py makemigrations
python manage.py migrate
然后我们登录数据库,连接数据库dj_experiment_db,输入show tables;就可以看到django创建的框架应用的表了
报错解决方案
报错代码:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2
使用python3.7+django2.2+pymysql时遇到这个错误,
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2
1
别急,这主要是django2.2内部的一个版本限制在作怪
处理方案
1.修复源码
按照文中配置,报错django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
原因:django2.2和pymysql版本不匹配。mysqldb不支持python3.
解决方案:
1、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.
解决办法:
C:\Python37\Lib\site-packages\django\db\backends\mysql(python安装目录)打开base.py,注释掉以下内容:
if version < (1, 3, 13): raise ImproperlyConfigured(‘mysqlclient 1.3.13 or newer is required; you have %s.’ % Database.version)
2、File “C:\Python37\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’
解决办法:
打开此文件把146行的decode修改为encode
找到安装python的这个位置
ps.django2.2不支持pyMySQL,但2.2是LTS,有想过试试mysqldb,但是MySQLDB又不支持python3。。。。的确让人头大。
————————————————
版权声明:本文为CSDN博主「温温净」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_45476498/article/details/100098297
- 点赞
- 收藏
- 分享
- 文章举报
- win10 下 django2.2生成mysql数据迁移文件出错(mysqlclient 1.3.13 or newer is required; you have 0.9.3)解决方法
- django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
- django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
- django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11
- macOS使用django安装mysqlclient遇到的问题(mysqlclient 1.3.3 or newer is required)
- Django连接mysql django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required;
- 解决 Django 的 if version (1, 3, 3): raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is requi
- mysql 5.5 主从同步数据到 msyql5.6数据库,报错为Slave is not configured or failed to initialize properly. You must
- SQL Server 2008R2安装错误—“is not a valid login or you do have permission”
- Can't find msguniq. Make sure you have GNU gettext tools 0.15 or newer installed.
- Caused by: com.mysql.cj.exceptions.UnableToConnectException: CLIENT_PLUGIN_AUTH is required
- docker 出现 client is newer than server 的解决方案
- MySQL数据库执行sql语句创建数据库和表提示The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to have
- XAMP下tomcat无法启动:Make sure you have Java JDK or JRE installed and the required ports are free解决方法
- 安装SQL Server 2008 R2 Enterprise错误:'' is not a valid login or you do not have permission
- Make sure you have Java JDK or JRE installed and the required ports are free
- Error:MySQLdb Module 'Did you install mysqlclient or MySQL-python?
- Django3.0和Python3.7连接Mysql报:Error loading MySQLdb module. Did you install mysqlclient?
- 解决The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to have it (http://ruijunsu)
- [MS bug]安装SQL Server 2008 错误:is not a valid login or you do not have permission