Django inspectdb问题使用Oracle数据库 [英] Django inspectdb issue using Oracle database

查看:1216
本文介绍了Django inspectdb问题使用Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装cx_oracle并运行inspectdb。似乎没有得到任何输出?有人可以帮助吗?使用inspectdb和Oracle有没有已知的问题?



下面是命令和settings.py。

  python manage.py inspectdb --database xxx_db 

#这是一个自动生成的Django模型模块。
#您必须手动清除以下内容:
#*重新排序模型的顺序
#*确保每个模型都有一个字段与primary_key = True
#随意重命名模型,但不要重命名db_table值或字段名称。

#还要注意:你必须将'django-admin.py sqlcustom [appname]'
#的输出插入你的数据库。

from django.db import models

settings.py

  DATABASES = {
'xxx_db':{
'ENGINE':'django.db.backends.oracle'
'NAME':'abc',
'USER':'abc_read',
'PASSWORD':'abc_read',
'HOST':'apps.domain.com ',
'PORT':'xxxx'
},
'default':{
'ENGINE':'django.db.backends.mysql',
'NAME':'aaaa',
'USER':'aaaa',
'PASSWORD':'xxxx',
'HOST':'/tmp/mysql.sock',
'PORT':''
}
}


方案

@Plecebo在正确的轨道上。 get_table_list方法是问题的根源,但是给出的Select语句不起作用。



我暂时硬编码表名以快速得到我需要的: p>

(django / db / backends / oracle / introspection.py第40行)

  def get_table_list(self,cursor):
返回当前数据库中的表名称列表。
#cursor.execute(SELECT TABLE_NAME FROM USER_TABLES)
return ['table_name1','table_name2']
#return [row [0] .lower fetchall()]


Installed cx_oracle and ran inspectdb. Don't seem to get any output? Can somebody help? Is there a known issue using inspectdb with Oracle?

Below is the command and settings.py.

python manage.py inspectdb --database xxx_db

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#     * Rearrange models' order
#     * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.

from django.db import models

settings.py

DATABASES = {
    'xxx_db': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': 'abc',
        'USER': 'abc_read',
        'PASSWORD': 'abc_read',
        'HOST': 'apps.domain.com',
        'PORT': 'xxxx'
        },
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'aaaa',
        'USER': 'aaaa',
        'PASSWORD': 'xxxx',
        'HOST': '/tmp/mysql.sock',
        'PORT': ''
        }
}

解决方案

@Plecebo is on the right track. The get_table_list method is the source of the problem, but the Select statement given did not work.

I temporarily hard coded the table names to quickly get what I needed:

(django/db/backends/oracle/introspection.py line 40)

def get_table_list(self, cursor):
    "Returns a list of table names in the current database."
    #cursor.execute("SELECT TABLE_NAME FROM USER_TABLES")
    return ['table_name1', 'table_name2']
    #return [row[0].lower() for row in cursor.fetchall()]

这篇关于Django inspectdb问题使用Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆