解决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/

相关推荐
Csvn8 小时前
🌟 LangChain 30 天保姆级教程 · Day 13|OutputParser 进阶!让 AI 输出自动转为结构化对象,并支持自动重试!
python·langchain
cch89189 小时前
Python主流框架全解析
开发语言·python
sg_knight9 小时前
设计模式实战:状态模式(State)
python·ui·设计模式·状态模式·state
好运的阿财9 小时前
process 工具与子agent管理机制详解
网络·人工智能·python·程序人生·ai编程
张張4089 小时前
(域格)环境搭建和编译
c语言·开发语言·python·ai
weixin_4235339910 小时前
【Windows11离线安装anaconda、python、vscode】
开发语言·vscode·python
Ricky111zzz10 小时前
leetcode学python记录1
python·算法·leetcode·职场和发展
小白学大数据10 小时前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
Hui Baby10 小时前
springboot读取配置文件
后端·python·flask
阿Y加油吧10 小时前
回溯法经典难题:N 皇后问题 深度解析 + 二分查找入门(搜索插入位置)
开发语言·python