相关疑难解决方法(0)

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

我正在使用数据库 Oracle 11g 在 Django-2.0.1 中启动一个项目,当我运行 $python manage.py migrate 时,出现错误 django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ( ORA-02000: 缺少 ALWAYS 关键字)。您可以在下面看到完整的堆栈:

   Traceback (most recent call last):
  File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/oracle/base.py", line 500, in execute
    return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.DatabaseError: ORA-02000: missing ALWAYS keyword

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in ensure_schema
    editor.create_model(self.Migration)
  File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 298, in create_model
    self.execute(sql, params …
Run Code Online (Sandbox Code Playgroud)

django oracle11g python-3.x django-migrations

5
推荐指数
1
解决办法
5461
查看次数

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

这是我的开发环境:

  • Windows 7(x64)
  • Python 3.6.3 64位(虚拟环境)
  • Django 2.0
  • cx_Oracle 6.1
  • Oracle 11.2 Enterprise Edition 64位(在远程计算机上)

我无法执行migrate(django manage.py migration),因为Django正在创建适用于Oracle 12c的sql。但我用的是11克

例如,django尝试执行以下命令:

SELECT
CASE WHEN identity_column = 'YES' THEN 1 ELSE 0 END
FROM user_tab_cols
WHERE table_name = 'DJANGO_CONTENT_TYPE' AND
column_name = 'NAME';
('DJANGO_CONTENT_TYPE', 'NAME'); 
args=['DJANGO_CONTENT_TYPE', 'NAME']
Run Code Online (Sandbox Code Playgroud)

但是该列identity_column在oracle 11g上不可用。

如何使django使用11g语法?

编辑:

追溯异常..\Lib\site-packages\django\db\backends\oracle\schema.py(在方法_is_identity_column151行中):

cursor.execute("""
                SELECT
                    CASE WHEN identity_column = 'YES' THEN 1 ELSE 0 END
                FROM user_tab_cols
                WHERE table_name = %s AND
                      column_name = …
Run Code Online (Sandbox Code Playgroud)

django oracle11g

2
推荐指数
1
解决办法
2796
查看次数

标签 统计

django ×2

oracle11g ×2

django-migrations ×1

python-3.x ×1