Hello everyone,
I’m new to Django development and I’m having a database connection problem that I would love your help with.
I’m using version 4.2 of Django, 8.3.0 of cx_Oracle, and 21.9 of Instant Client. My Oracle server is version 12.2 and I can’t update it.
When trying to connect, I get the following exception: Oracle 19 or later is required (found 12.2.0.1.0).
Here’s my settings.py file:
cx_Oracle.init_oracle_client(lib_dir=r"C:/app/instantclient_21_9")
os.environ["TNS_ADMIN"] = r"C:/app/oracleconfig"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'xxxx',
'USER': 'xxxx',
'PASSWORD': 'xxxx',
'HOST': 'xxxx',
'PORT': 'xxxx',
},
'oracle': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'xxxx',
'USER': 'xxxx',
'PASSWORD': 'xxxx',
'HOST': 'xxxx',
'PORT': 'xxxx',
},
}
And here’s my function:
from django.db import connections
def test_oracle_connection():
try:
connection = connections['oracle']
cursor = connection.cursor()
cursor.execute('SELECT 1 FROM DUAL')
result = cursor.fetchone()
cursor.close()
return result[0] == 1
except Exception as e:
print(str(e))
return False
Thanks for your help!