标签:python oracle django database inspectdb
安装了cx_oracle并运行了inspectdb.似乎没有任何输出?有人可以帮忙吗?使用inspectdb和Oracle有一个已知问题吗?
下面是命令和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': ''
}
}
解决方法:
两件事情:
> Inspectdb没有正式支持oracle(见Django Docs – inspectdb)悲伤的时候.
> Django对Oracle模式没有很强的支持(参见unresolved Django ticket 6148)如果你能够使用主要用户连接模式,那么你可能会有更好的运气,使你想要反省默认模式的模式.
通过更改introspection.py中的select,我能够获得基本的模型文件输出.对我来说,我改变了django / db / backends / oracle / introspection.py(第40行附近)中的get_table_list函数:
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 [row[0].lower() for row in cursor.fetchall()]
至
def get_table_list(self, cursor):
"Returns a list of table names in the current database."
cursor.execute("SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = 'SCHEMA_TO_QUERY'")
return [row[0].lower() for row in cursor.fetchall()]
但是当我读到Oracle对模式的整体支持不足时,放弃了django
标签:python,oracle,django,database,inspectdb 来源: https://codeday.me/bug/20191007/1866782.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。