Django,使用 oracledb 错误消息,我需要 Oracle 19

问题描述 投票:0回答:3

我很困惑,因为 oracledb 的文档明确指出 12.1 之后的所有内容都应该可以正常工作。有人可以向我解释一下我哪里出错了吗?当我尝试创建迁移时,出现了该错误。 我引用的文档是:oracledb docs

这是错误:

django.db.utils.NotSupportedError: Oracle 19 or later is required (found 12.2.0.1.0).

这是我的settings.py 中的数据库字符串:

from pathlib import Path
import sys
import oracledb
oracledb.version = "8.3.0"
sys.modules["cx_Oracle"] = oracledb
#the above line was added because of error (django.core.exceptions.ImproperlyConfigured: Error 
#loading cx_Oracle module: No module named 'cx_Oracle')

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': (
                    '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server123)(PORT=1521))'
                    '(CONNECT_DATA=(SERVICE_NAME=server.domain.com)))'
                ),
        'USER': 'user123',
        'PASSWORD': 'password',
        'OPTIONS': {
            'threaded': True,
            
        },
    }
}
django django-models cx-oracle python-oracledb
3个回答
2
投票

这是 Django 的事情。来自 docs.djangoproject.com/en/4.1/ref/databases/#oracle-notes

“Django 支持 Oracle 数据库服务器版本 19c 及更高版本。”

另请参阅 Django 4.0 发行说明

“放弃对 Oracle 12.2 和 18c 的支持”。

如果无法升级数据库,请尝试旧版本的 Django


2
投票

如果无法升级数据库,可以尝试更改minimum_database_version的值。 在 mysite/mydbengine/base.py 中

from django.db.backends.oracle import base, features


class DatabaseFeatures(features.DatabaseFeatures):
    minimum_database_version = (12,)

class DatabaseWrapper(base.DatabaseWrapper):
    features_class = DatabaseFeatures

在settings.py中

DATABASES = {
'default': {
    'ENGINE': 'mydbengine',
    ...
}

另请参阅 https://docs.djangoproject.com/en/4.2/ref/databases/#subclassing-the-built-in-database-backends


0
投票

您必须注释方法init_connection_state()。请务必在虚拟环境中评论该行并记录下来。

这是venv内的相对路径:

。 env\Lib\site-packages\django\db 确认 ase ase.py

© www.soinside.com 2019 - 2024. All rights reserved.