关于django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3错误的处理办法

最近,很多朋友都把自己的操作系统、Python、Django都升级到最新版本了,使用默认SQLite数据,运行时会报出类似django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3的错误提示。这主要是操作系统默认SQLite数据库版本太低造成的。这里给大家提供三种解决办法,希望能帮到大家。

第一种:

升级系统里的SQLite版本。方法:https://www.django.cn/forum/forum-487.html

注意,如需要最新版本的话,请从官网下载最新的软件包。 下载址:https://www.sqlite.org/download.html

第二种:找到报错文件,如/usr/local/python3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py 打开它,找到

def check_sqlite_version():
    if Database.sqlite_version_info < (3, 9, 0):

把里面小括号里的 SQLite版本(3,9,0)修改成你当前系统里版本就好。

第三种:

使用第三方包运行SQLite。把sqlite3 更换为pysqlite3 和 pysqlite3-binary方法:

1、安装pysqlite3和pysqlite3-binary

pip install pysqlite3
pip install pysqlite3-binary

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

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

三种,总有一种适合你。

评论 3

  • 请问一下,为什么我安装pysqlite3-binary,提示“Could not find a version that satisfies the requirement pysqlite3-binary (from versions: none)”,我的Python3版本为3.10.5,pip3版本为22.1.2,系统是CentOS 7.9.2009

  • 在腾讯云的CentOS 7系列,用Python3.10,Django4.1.2试过,以上三种方法都不行。 方法二,已经没有这个函数了。 方法三,pip install pysqlite3-binary这一步会失败。

    然后换成了CentOS 8和Ubuntu 20系列就没有这个Sqlite3的问题。