django.db.utils.DatabaseError: ORA-12154: TNS: Die in OCI angegebene Verbindungskennung konnte nicht aufgelöst werden.

django.db.utils.DatabaseError: ORA-12154: TNS: Die in OCI angegebene Verbindungskennung konnte nicht aufgelöst werden.
django.db.utils.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

innerhalb von OCI treten wiederholt Fehler beim Verbinden mit der Datenbank ADW (Autonomous Database Warehouse 19c) auf, um ein Django-Projekt in der Oracle-Cloud-Infrastruktur bereitzustellen

 uname -a
Linux instance-20210913-1957 5.4.17-2102.204.4.4.el7uek.x86_64 #2 SMP Tue Aug 17 20:25:28 PDT 2021 x86_64 x86_64 x86_64 GNU/Linux

pip freeze
asgiref==3.4.1
cx-Oracle==8.0.0
Django==3.2.7
pytz==2021.1
sqlparse==0.4.2
typing-extensions==3.10.0.2

Ich habe die regionale Wallet-Datei in /usr/lib/oracle/21/client64/lib/network/admin entpackt

meine sttings.py

DATABASES={
    'default':
    {
    'ENGINE':'django.db.backends.oracle',
    'NAME':'potatodbname',
    'USER':'ADMIN',
    'PASSWORD':'wieredpassword',#Please provide the db password here
    }
}

kompletter Fehler:

 python manage.py migrate
Traceback (most recent call last):
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/oracle/base.py", line 233, in get_new_connection
    **conn_params,
cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/core/management/commands/migrate.py", line 92, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/migrations/loader.py", line 53, in __init__
    self.build_graph()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/migrations/loader.py", line 220, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
    if self.has_table():
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
    with self.connection.cursor() as cursor:
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
    return self._cursor()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
    self.ensure_connection()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/var/www/cgi-bin/trydjango-dev/lib64/python3.6/site-packages/django/db/backends/oracle/base.py", line 233, in get_new_connection
    **conn_params,
django.db.utils.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

was habe ich übersehen, um diesen Fehler zu bekommen?

Antwort1

Korrektur in settings.py:

DATABASES={
    'default':
    {
    'ENGINE':'django.db.backends.oracle',
    'NAME':'servicename', # must be the servicename eg. dbname_high,dbname_low,dbname_medium etc.
    'USER':'ADMIN',
    'PASSWORD':'bhouguspassword',#Please provide the db password here but it can cause issue if you were using '@'
    }
}

Weg:

ls -lart /usr/lib/oracle/21/

Ich habe die Brieftasche im ?/network/adminOrdner entpackt und die Gruppenberechtigung auf Apache geändert. chown -R :apache /usr/lib/oracle/21/ Stellen Sie sicher, dass Sie TNS_ADMIN und LD_LIBRARY_PATH ordnungsgemäß eingerichtet haben.

python manage.py migrate

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK

Wenn ACL aktiviert ist, bearbeiten Sie es mit Ihrer IP, CIDR und VCN

Danke

verwandte Informationen