2016-02-29 55 views
4

我的數據庫設置連接到傳統的Oracle數據庫後端是如何使用cx_oracle django包連接到oracle舊數據庫?

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

我使用這個命令使用

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

我的問題是下面

運行創造models.py文件
  • 當我運行它如上所述命令創建一個空models.py文件

    from __future__ import unicode_literals 
    from django.db import models 
    

我做了很多研究,但無法找到一個方法來創建models.py文件與cx_oracle包oracle數據庫後臺,請大家幫忙。我是一隻新的蜜蜂。

回答

3

我解決了這個問題,與使用django連接其他數據庫(postgres,mysql等)不同,要訪問oracle legacy數據庫,models.py文件需要手動創建。 在我的情況下python manage.py inspectdb --database=bannerdb >models.py沒有工作。我創建models.py文件爲

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" 

使用oracle數據庫後端的完整說明是http://www.oracle.com/technetwork/articles/dsl/vasiliev-django-100257.html

相關問題