Django - deterministic=True在运行python www.example.com runserver时需要SQLite 3.8.3或更高manage.py版本

laik7k3q  于 2022-12-24  发布在  Go
关注(0)|答案(5)|浏览(278)

我正在运行一个来自AWS的Linux红帽环境。
我已经遵循了将sqlite3升级到"最新"版本的每一个指示。
我运行的是python 3.9.2(已经用LD_RUN_PATH=/usr/local/lib ./configure重新编译过了)和django版本4。
我已经建立了一个虚拟环境来安装和运行django。我已经修改了激活脚本来包含export LD_LIBRARY_PATH="/usr/local/lib"
在运行python manage.py runserver时,我得到了错误django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher。我打开了文件/home/ec2-user/django/django/db/backends/sqlite3/base.py(错误发生的地方),在错误行后面包含了一个print语句:

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

其返回:

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

请让我知道需要什么额外的信息。我已经搜索了stack,但没有找到正确的解决方案pop这一关。
先谢谢你!
编辑
下面是回溯:

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
brgchamk

brgchamk1#

我在我的linux Centos7+python3.9.6+Django3.2.5中遇到了同样的问题,尽管sqlite3已经更新到最新版本,但似乎没有用,一种解决方法是将数据库从sqlite3改为pysqlite3,激活virtualenv后安装pysqlite

pip3 install pysqlite3
pip3 install pysqlite3-binary

并在www.example.com中更改数据库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

重新启动django服务器和它的作品.

qpgpyjmq

qpgpyjmq2#

当我尝试在Elastic Beanstalk上部署时,我遇到了与您相同的问题。在我使用Python 3.8的情况下,当我初始化EB CLI时,如下所示:

eb init -p python-3.8 django-project ⛔

这不是一个在64位Amazon Linux 2(默认)上运行它的好Python版本。请更改为Python-3. 7

eb init -p python-3.7 django-project ✅
quhf5bfb

quhf5bfb3#

用正确的环境重新编译python3可以解决这个问题,下面是重新编译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

然后可以在python中通过以下命令执行检查

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

js4nwp544#

目前我能想到的最好的办法是进入/home/ec2-user/django/django/db/backends/sqlite3/base.py,将get_new_connection()中的函数变量deterministic=True更改为deterministic=False ...
这将删 debugging 误,但似乎是一个超级欺骗的解决方案。如果任何人有更好的修复,请让我知道。

vptzau2j

vptzau2j5#

使用PostgreSQL是一个不错的选择,因为它确实支持python 3.8并解决了这个错误。同样,正如在question中解释的那样,使用PostgreSQL进行生产会更好。话虽如此,我推荐这个教程,它教如何在eb上运行postgres。尽管它有点过时,但对我来说非常有用。

相关问题