解决django与sqlite3不兼容报SQLite 3.9.0 or later is required错的问题

今天在尝试用pytest进行django的单元测试,pytest用的数据库是sqlite3,在window环境下测试得好好的,但是放到linux环境下就报错,具体是报django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.8.2).的错。

从报错的提示看是sqlite3的版本太低,期望是3.9.0但是当前版本是3.8.2

在网上找了很多资料,也都是说django与sqlite3的版本不兼容,需要升级sqlite3的版本。

于是将sqlite3升级到目前的稳定版本3.46.0,然而发现并没有什么用,还是报sqlite3.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher

通过sqlite3 --version 查看版本号已经是3.46.0了,但还是提示要求SQLite版本在3.8.3以上。重装django4和python3.8的环境都没有用。

最后在网上找到解决办法。使用第三方包pysqlite3运行SQLite3

具体方法如下:

1、安装pysqlite3和pysqlite3-binary

powershell 复制代码
pip install pysqlite3
pip install pysqlite3-binary

2、找到django的sqlite3驱动包,/usr/local/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py 找到 from sqlite3 import dbapi2 as Database 注释它,添加代码

python 复制代码
#from sqlite3 import dbapi2 as Database  #注释它
from pysqlite3 import dbapi2 as Database #新加这段代码

历经周折终于解决。


博客地址:http://xiejava.ishareread.com/

相关推荐
龙潜月七3 分钟前
Selenium 自动化测试中跳过机器人验证的完整指南:能用
python·selenium·机器人
蓝婷儿2 小时前
Python 机器学习核心入门与实战进阶 Day 1 - 分类 vs 回归
python·机器学习·分类
Devil枫3 小时前
Kotlin扩展函数与属性
开发语言·python·kotlin
.30-06Springfield3 小时前
利用人名语言分类案例演示RNN、LSTM和GRU的区别(基于PyTorch)
人工智能·pytorch·python·rnn·分类·gru·lstm
程序员阿超的博客4 小时前
Python 数据分析与机器学习入门 (八):用 Scikit-Learn 跑通第一个机器学习模型
python·机器学习·数据分析·scikit-learn·入门教程·python教程
xingshanchang5 小时前
PyTorch 不支持旧GPU的异常状态与解决方案:CUDNN_STATUS_NOT_SUPPORTED_ARCH_MISMATCH
人工智能·pytorch·python
费弗里8 小时前
Python全栈应用开发利器Dash 3.x新版本介绍(1)
python·dash
李少兄9 天前
解决OSS存储桶未创建导致的XML错误
xml·开发语言·python
就叫飞六吧9 天前
基于keepalived、vip实现高可用nginx (centos)
python·nginx·centos
Vertira9 天前
PyTorch中的permute, transpose, view, reshape和flatten函数详解(已解决)
人工智能·pytorch·python