【问题标题】:configure the django with Oracle 11g data base issue使用 Oracle 11g 数据库问题配置 django
【发布时间】:2018-08-20 03:28:14
【问题描述】:

Oracle 数据库配置与 Django 并在迁移应用程序时面临错误

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

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

}

【问题讨论】:

    标签: python django oracle


    【解决方案1】:

    删除上述代码中的self.cursor.numbersAsStrings = True

    【讨论】:

    • 我爱你,谢谢!上面的代码没有帮助我
    • 非常好的通知。上次没找到这个,强行编辑编译oracle客户端lib的c源代码。谢谢!
    【解决方案2】:

    问题是 Django 2.0.2 只支持 oracle 12g。检查这个:

    How to make Django 2.0 to use Oracle 11g syntax instead of 12c?

    此外,您可以检查 sql 失败,如以下问题中所指出的(在 manage.py 中添加 print(query) 行)

    Unable to create the django_migrations table (ORA-02000: missing ALWAYS keyword)

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

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

    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',
    }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-25
      • 2021-03-27
      • 2011-06-22
      • 1970-01-01
      • 2014-11-04
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多