[Django]-Django – deterministic=True requires SQLite 3.8.3 or higher upon running python manage.py runserver

21👍

I came across the same issue in my linux Centos7+python3.9.6+Django3.2.5.
Althougt the sqlite3 is updated to the lastest version. It seems that this is useless. A kind of solution is changing the database from sqlite3 to pysqlite3.
After acticate the virtualenv, install pysqlite

pip3 install pysqlite3
pip3 install pysqlite3-binary

and change db in base.py

vim python3.9.6/site-packages/django/db/backends/sqlite3/base.py

# from sqlite3 import dbapi2 as Database # annotation
from pysqlite3 import dbapi2 as Database # import pysqlite3

restart django server and it works.

👤sa lei

5👍

enter image description here

I have got the same problem as yours. when I tried to deploy on Elastic Beanstalk.
In my case used Python 3.8 when I initialized EB CLI like this:

eb init -p python-3.8 django-project ⛔

and that not a good python version to run it on 64bit Amazon Linux 2 (default). change to python-3.7

eb init -p python-3.7 django-project ✅

5👍

It can be solved by recompiling python3 with the correct environment. Below are the commands for recompiling python3.

export C_INCLUDE_PATH=/PATH_TO_SQLITE/include
export CPLUS_INCLUDE_PATH=/PATH_TO_SQLITE/include 
export LD_RUN_PATH=/PATH_TO_SQLITE/lib
./configure --prefix=/PATH_FOR_PYTHON 
make
make install

Then a check can be done in python by the below commands

import sqlite3 
conn = sqlite3.connect(':memory:') 
conn.create_function('f', 2, lambda *args: None, deterministic=True) 

2👍

The best I can figure at the moment is to go into /home/ec2-user/django/django/db/backends/sqlite3/base.py, change the function variable deterministic=True in get_new_connection() to deterministic=False

This will remove the error, but seems like a super cheaty solution. If anyone has a better fix, please let me know.

👤Shmack

0👍

Using PostgreSQL is a good choice as it does support python 3.8 and solves this error. Also as in this question is explained that it is better to use postgreSQL for production. Having said that I recommend this tutorial that teaches how to run postgres on eb. Despite it is a bit outdated it was for me very useful.

-3👍

安装 pip3 install pysqlite3
打开文件/usr/local/python3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py,找到 from sqlite3 import dbapi2 as Database 注释它,替换为from pysqlite3 import dbapi2 as Database

vim /u01/apps/python3/lib/python3.10/site-packages/django/db/backends/sqlite3/_functions.py 将deterministic=True中的函数变量get_new_connection()更改为deterministic=False ..

然后

vim /u01/apps/python3/lib/python3.10/site-packages/django/db/backends/base/base.py# def : check_database_version_supported 里面的方法注释掉 写上pass

如:
def check_database_version_supported(self):
pass
"""
Raise an error if the database version isn’t supported by this
version of Django.
"""

👤J丶JP

Leave a comment