26

I am running a linux red hat environment from AWS.

I have followed every instruction for upgrading sqlite3 to the "latest" version.

I am running python 3.9.2 (and have recompiled it with LD_RUN_PATH=/usr/local/lib ./configure) and django version 4.

I have set up a virtual environment to install and run django. I have changed the activate script to include export LD_LIBRARY_PATH="/usr/local/lib"

Upon running python manage.py runserver, I get the error django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher. I have opened the file /home/ec2-user/django/django/db/backends/sqlite3/base.py (where the error occurs) and right after the line with the error have include a print statement:

print("**************************\n" +
    str(Database.sqlite_version) +
    "\n" + str(Database.sqlite_version_info) +
    "\n**************************")

which retruns:

**************************
3.28.0
(3, 28, 0)
**************************
**************************
3.28.0
(3, 28, 0)
**************************

Please let me know what additional information is needed. I have searched up and down the stack and can't find the right solution to pop this one off.

Thank you in advance!

EDIT

Here is the traceback:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/ec2-user/django/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/home/ec2-user/django/django/utils/asyncio.py", 21 in inner
    return func(*args, **kwargs)
  File "/home/ec2-user/django/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ec2-user/django/django/db/backends/sqlite3/base.py", line 210, in get_new_connection
    create_deterministic_function('django_date_extract', 2, _sqlite_datetime_extract)
sqlite3.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/python/lib/python/3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/opt/python39/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ec2-user/django/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/ec2-user/django/django/core/management/commands/runserver.py", line 126, in inner_run
    self.check_migrations()
  File "/home/ec2-user/django/django/core/management/base.py", line 486, in check_migrations
    executor = MigrationExecutor(connectsion[DEFAULT_DB_ALIAS])
  File "/home/ec2-user/django/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/ec2-user/django/django/db/migrations/loader.py", line 53, in __init__
    self.build_graph()
  File "/home/ec2-user/django/django/db/migrations/loader.py", line 220, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/ec2-user/django/django/db/migrations/recorder.py", line 77, in applied_migrations
    if self.has_table():
  File "/home/ec2-user/django/django/db/migrations/recorder.py", line 55, in has_table
    with self.connection.cursor() as cursor:
  File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ec2-user/django/django/db/backends/base/base.py", line 259, in cursor
    return self._cursor()
  File "/home/ec2-user/django/django/db/backends/base/base.py", line 235, in _cursor
    self.ensure_connection()
  File "/home/ec2-user/django/djanog/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ec2-user/django/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/home/ec2-user/django/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/ec2-user/django/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ec2-user/django/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/home/ec2-user/django/django/db/backends/sqlite3/base.py", line 210, in get_new_connection
    create_deterministic_function('django_date_extract', 2, _sqlite_datetime_extract)
django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
Shmack
  • 1,933
  • 2
  • 18
  • 23

6 Answers6

20

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
  • 216
  • 2
  • 3
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) 
Jaebak Kim
  • 51
  • 1
  • 1
  • Its going to be a while before I can test this, so I am going to upvote, because this seems like the intuitive answer, though I mentioned in the post that I did recompile, I probably didn't export the variables before doing so, or include the path to Python. – Shmack Dec 21 '22 at 17:32
  • Confirming this is the perfect solution for me. (CentOS 7, manually updated: python3.9, sqlite3.40). Because, most of the solutions online for this problem mentions set LD_RUN_PATH to statically link sqlite3, but no one mentions you have to include header files using C_INCLUDE_PATH and CPLUS_INCLUDE_PATH. thank you. @Jaebak Kim – user1835157 Jan 04 '23 at 14:39
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
  • 1,933
  • 2
  • 18
  • 23
  • this actually works. gosh. i stuck on this for days... i know it's sketchy, but still... i'll do more research. all of my focus was on the wrong direction. i thought it was the sqlite3 version. – user1835157 Jan 04 '23 at 11:42
  • @user1835157 Well, there are definitely problems with this. 1. You can't upgrade django without having to redo this. 2. I don't know if it breaks the django models, but it very much may. 3. If the django models are broken, you probably can't use `celery` (a common library with django). 4. Recompiling python after you install sqlite3 seems like it should work and be objectively best -> @JaebakKim's answer. – Shmack Jan 04 '23 at 15:26
  • 1
    thanks again for the heads up. i'm only doing this as learning and testing. after i tried you solution, i kept trying other ways. you're right, recompiling with correct including and linking options is the RIGHT way i suppose. – user1835157 Jan 04 '23 at 15:56
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.

-2

安装 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
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 09 '23 at 13:17
  • Yah. we are going to need you to clarify your answer, and try to fix your formatting. – Shmack Jan 09 '23 at 15:35