Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to oracle legacy database using cx_oracle django package?

My database settings to connect to legacy oracle database backend are

DATABASES = { 'bannerdb': { 'ENGINE': 'django.db.backends.oracle', 'NAME': 'host:port/service_name', 'USER': 'username', 'PASSWORD': 'password', },

I am using this command to run create models.py file using

python manage.py inspectdb --database=bannerdb >models.py

My question is the following

  • when I run the inspectdb command as mentioned above it creates an empty models.py file as

     from __future__ import unicode_literals
     from django.db import models
    

I did lot research but was unable to find a way to create models.py file for the oracle database backend with cx_oracle package, please help. I am a new bee.

like image 366
javed Avatar asked Oct 18 '22 14:10

javed


1 Answers

I resolved this issue, unlike connecting with other databases (postgres, mysql etc) using django, to access oracle legacy database the models.py file needs to be created manually. In my case python manage.py inspectdb --database=bannerdb >models.py did not work. I created the models.py file as

class table_name(models.Model):
    ID = models.CharField(max_length=9, primary_key=True)
    title = models.CharField(max_length=20, null=True)
    first_name = models.CharField(max_length=60, null=True)
    middle_name = models.CharField(max_length=60, null=True)
    last_name = models.CharField(max_length=60)

    class Meta:
        db_table="table_name_oracle_database"

Full explanation of using oracle database back end is here http://www.oracle.com/technetwork/articles/dsl/vasiliev-django-100257.html.

like image 126
javed Avatar answered Nov 01 '22 07:11

javed