繁体   English   中英

使用Oracle 11g数据库问题配置django

[英]configure the django with Oracle 11g data base issue

使用Django进行Oracle数据库配置,同时迁移面临错误的应用程序

django.db.migrations.exceptions.MigrationSchemaMissing:无法创建dja ngo_migrations表(ORA-02000:缺少ALWAYS关键字)

application environment 
1.windows10
2.Python 3.6.x
3.Django 2.0.2
4.oracle 11g XE
in settins.py file 
DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.oracle',
    'NAME': 'xe',
    'USER': 'abc',
    'PASSWORD':'xxxx',
    'HOST':'localhost',
    'PORT':"1521",

}

问题是Django 2.0.2只支持oracle 12g。 检查一下:

如何让Django 2.0使用Oracle 11g语法而不是12c?

此外,您可以检查sql失败,如下面的问题所示(添加到manage.py打印(查询)行)

无法创建django_migrations表(ORA-02000:缺少ALWAYS关键字)

我按照第一个问题的建议降级到Django 1.11,但这导致我错误“AttributeError:'cx_Oracle.Cursor'对象没有属性'numbersAsStrings'”因为我已经安装了最后一个cx_Oracle版本。 (更多信息请访问: https//code.djangoproject.com/ticket/28138

为了解决这个问题,我将文件C:\\ Program Files \\ Python37 \\ lib \\ site-packages \\ django \\ db \\ backends \\ oracle \\ base.py修改为:

def __init__(self, connection):
     self.cursor = connection.cursor()
     # Necessary to retrieve decimal values without rounding error.
     self.cursor.numbersAsStrings = True
     self.cursor.outputtypehandler = self._output_type_handler
     # Default arraysize of 1 is highly sub-optimal.
     self.cursor.arraysize = 100
     # https://github.com/django/django/commit/d52577b62b3138674807ac74251fab7faed48331

 @staticmethod
 def _output_type_handler(cursor, name, defaultType, length, precision, scale):
     """
     Called for each db column fetched from cursors. Return numbers as
     strings so that decimal values don't have rounding error.
     """
     if defaultType == Database.NUMBER:
         return cursor.var(
             Database.STRING,
             size=255,
             arraysize=cursor.arraysize,
             outconverter=str,
         )

我从这里开始使用此代码块:

https://github.com/cloudera/hue/commit/07d85f46eeec9c8c19d9aa11d131638e2a99e65c#diff-6d9bd161753aad635c23c2e91efafe91

有了这个,我至少能够迁移项目。 我不知道在走得更远的时候是否会失败。

希望这可以帮助!

PD:我认为你的DATABASES设置应该如http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/oow10/python_django/python_django.htm

DATABASES = {
'default': {
    'ENGINE':   'django.db.backends.oracle',
    'NAME':     'localhost/orcl',
    'USER':     'pythonhol',
    'PASSWORD': 'welcome',
}}

在上面提到的代码中删除self.cursor.numbersAsStrings = True

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM