首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Django - deterministic=True运行python时需要SQLite 3.8.3或更高版本

Django - deterministic=True运行python时需要SQLite 3.8.3或更高版本
EN

Stack Overflow用户
提问于 2021-02-26 04:10:55
回答 4查看 6.9K关注 0票数 20

我正在运行来自AWS的linux红帽环境。

我遵循了将sqlite3升级到“最新”版本的每一条指令。

我正在运行python3.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语句:

代码语言:javascript
运行
复制
print("**************************\n" +
    str(Database.sqlite_version) +
    "\n" + str(Database.sqlite_version_info) +
    "\n**************************")

其中反过来说:

代码语言:javascript
运行
复制
**************************
3.28.0
(3, 28, 0)
**************************
**************************
3.28.0
(3, 28, 0)
**************************

请告诉我需要什么额外的信息。我在stack上搜索了一下,却找不到合适的pop解决方案。

提前谢谢你!

编辑

这是回溯:

代码语言:javascript
运行
复制
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
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2021-08-21 02:58:54

我在我的linux Centos7+python3.9.6+Django3.2.5中遇到了同样的问题。尽管sqlite3被更新为最新的版本。看来这是没用的。一种解决方案是将数据库从sqlite3更改为pysqlite3。完成虚拟环境后,安装pysqlite

代码语言:javascript
运行
复制
pip3 install pysqlite3
pip3 install pysqlite3-binary

并在base.py中更改db

代码语言:javascript
运行
复制
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服务器,它就能工作了。

票数 13
EN

Stack Overflow用户

发布于 2021-12-18 23:51:54

我和你有同样的问题。当我试图在弹性豆柄上部署时。在我的例子中,我在初始化时使用了Python3.8CLI,如下所示:

代码语言:javascript
运行
复制
eb init -p python-3.8 django-project ⛔

而且,在64位Amazon 2(默认)上运行它也不是一个好的python版本。改为python-3.7

代码语言:javascript
运行
复制
eb init -p python-3.7 django-project ✅
票数 5
EN

Stack Overflow用户

发布于 2022-08-22 17:51:38

可以通过使用正确的环境重新编译python3来解决这个问题。下面是重新编译python3的命令。

代码语言:javascript
运行
复制
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中进行检查

代码语言:javascript
运行
复制
import sqlite3 
conn = sqlite3.connect(':memory:') 
conn.create_function('f', 2, lambda *args: None, deterministic=True) 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66380006

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档