我正在使用数据库 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) 这是我的开发环境:
我无法执行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)