如何使用 cx_oracle django 包连接到 oracle 遗留数据库?
How to connect to oracle legacy database using cx_oracle django package?
我连接到旧版 Oracle 数据库后端的数据库设置是
DATABASES = {
'bannerdb': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'host:port/service_name',
'USER': 'username',
'PASSWORD': 'password',
},
我正在使用此命令 运行 使用
创建 models.py 文件
python manage.py inspectdb --database=bannerdb >models.py
我的问题如下
当我 运行 上面提到的 inspectdb
命令时,它会创建一个空的 models.py
文件作为
from __future__ import unicode_literals
from django.db import models
我做了很多研究,但无法找到使用 cx_oracle 包为 oracle 数据库后端创建 models.py
文件的方法,请帮忙。我是一只新蜜蜂
我解决了这个问题,与使用 django 连接其他数据库(postgres、mysql 等)不同,要访问 oracle 遗留数据库,需要手动创建 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。
我连接到旧版 Oracle 数据库后端的数据库设置是
DATABASES = {
'bannerdb': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'host:port/service_name',
'USER': 'username',
'PASSWORD': 'password',
},
我正在使用此命令 运行 使用
创建 models.py 文件python manage.py inspectdb --database=bannerdb >models.py
我的问题如下
当我 运行 上面提到的
inspectdb
命令时,它会创建一个空的models.py
文件作为from __future__ import unicode_literals from django.db import models
我做了很多研究,但无法找到使用 cx_oracle 包为 oracle 数据库后端创建 models.py
文件的方法,请帮忙。我是一只新蜜蜂
我解决了这个问题,与使用 django 连接其他数据库(postgres、mysql 等)不同,要访问 oracle 遗留数据库,需要手动创建 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。