Javed
Javed

Reputation: 6239

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

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.

Upvotes: 5

Views: 2525

Answers (1)

Javed
Javed

Reputation: 6239

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.

Upvotes: 3

Related Questions