G
G
Gourii2020-12-12 17:21:24
Django
Gourii, 2020-12-12 17:21:24

How to fix sqlite3 error in django?

Hello.
I have a django test project that starts and runs fine on Windows 7, but does not work on Linux Ubuntu Server.
The essence of the problem, when starting the django test server, an error occurs:

Mistake

*****@ServerUbuntu:~/samba/share/Projects/test_site$ python3.8 manage.py runserver
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/*****/.local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/*****/.local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/*****/.local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 215, 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 "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check_migrations()
File "/home/*****/.local/lib/python3.8/site-packages/django/core/management/base.py", line 459, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/home/*****/.local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/*****/.local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/home/*****/.local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/*****/.local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/home/*****/.local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/home/*****/.local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/home/*****/.local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/*****/.local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/*****/.local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/*****/.local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/*****/.local/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 215, 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

Django swears at SQLite, although the latest version is installed:

*****@ServerUbuntu:~/samba/share/Projects/test_site$ sqlite3 --version
3.34.0 2020-12-01 16:14:00 a26b6597e3ae272231b96f9982c3bcc17ddec2f2b6eb4df06a224b91089fed5b

If you look at the version of sqlite3 in python, then the version is as follows:

*****@ServerUbuntu:~/samba/share/Projects/test_site$ python3.8
Python 3.8.6 (default, Dec 12 2020 08:29:04)
[GCC 5.4.0 20160609] on linux
Type "help ", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.11.0'

After reading the forums, I tried different solutions to the problem, reinstalled sqlite, rebuilt python, nothing helps.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Gourii, 2020-12-17
@Gourii

In general, I solved the problem, installed Django version 3.0.
If there is an error when starting the project:


return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'PosixPath' is not iterable

Then in the project settings in the database name line, write str

'NAME': str(BASE_DIR / 'db.sqlite3')

M
mkone112, 2020-12-12
@mkone112

Maybe pip install -U sqlite3?

S
Sergey Eremin, 2020-12-12
@Sergei_Erjemin

Something with django_date_extract ... In general, SQLite has a bit strange date-time processing, and in time zones it gets confused from version to version, and in formats ... I would look aside if the formation of date-time is specified in your project , when you "thrust" this date-time in a kind term in a DB. On home and commercial systems, the default formats can be different, and it is more reliable to do all conversions of strings like 2020-12-14 15:27:00.000 MSK to date-time not to get the database, but to do it on the Python side...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question