问题是 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',
}}