- Ensure that cx_oracle is installed (Please see the References section for details).
- Locate/ create file tnsnames.ora
In case Oracle DB or client is installed, you can try to locate the file under ORACLE_HOME/network/admin/
- Add an entry for the target host and service name to tnsnames.ora
Example:This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersMYORA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ORA11) ) ) - Ensure that TNS_ADMIN environment variable is set to the folder containing tnsnames.ora
- Change the database connection in Django settings file to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersDATABASES = { 'default': { 'ENGINE': 'django.db.backends.oracle', 'NAME': 'MYORA', #the name for the entry in tnsnames.ora 'USER': '<username>', 'PASSWORD': '<password>', } } - Now, you are ready to connect to Oracle db.
References:
- http://codeforaliving.blogspot.com/2015/02/installing-cxoracle-on-ubuntu_73.html
- http://www.orafaq.com/wiki/Tnsnames.ora
- https://docs.djangoproject.com/en/1.7/ref/databases/ (Please see the section related to Oracle)