使用Oracle 11g数据库配置django问题 [英] configure the django with Oracle 11g data base issue

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

问题描述

使用Django进行Oracle数据库配置,并在迁移应用程序时遇到错误

Oracle database configurations with Django and while migrating the application facing the error

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

django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the dja ngo_migrations table (ORA-02000: missing ALWAYS keyword)

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.检查一下:

The problem is that Django 2.0.2 only supports oracle 12g. Check this:

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

此外,您还可以按照以下问题中的指示检查sql失败(在manage.py中添加一条print(query)行)

Also, you can check the sql failing, as pointed in the following question (adding to the manage.py a print(query) line)

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

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

I've downgrade to Django 1.11 as recommended in the first question, but this leaded me to the error "AttributeError: 'cx_Oracle.Cursor' object has no attribute 'numbersAsStrings'" because I have installed the last cx_Oracle version. (more information here: https://code.djangoproject.com/ticket/28138)

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

To fix this, I've modify the file C:\Program Files\Python37\lib\site-packages\django\db\backends\oracle\base.py to this:

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,
         )

我从这里获取了此代码块:

I've take this code block from here:

https://github.com/cloudera/huefd93c65e9e85e9e85c3e9e85e46e #diff-6d9bd161753aad635c23c2e91efafe91

有了这个,至少我已经能够迁移项目了.我不知道它在继续前进时是否会失败.

With this, I've been able to migrate the project, at least. I don't know if it will fail while going further.

希望这会有所帮助!

PD:我认为您的数据库设置应与

PD: I think your DATABASES setting should be as in 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',
}}

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

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