无法在python 3.7中使用cx_oracle 6.4将Django 2.0.7与oracle 12c连接

时间:2018-07-06 10:58:32

标签: python django oracle12c cx-oracle django-2.0

我在将 Orace 12c Django 2

连接时遇到问题

使用的命令:python manage.py migrate

以下是我收到的错误消息

Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0002_remove_content_type_name...Traceback (most recent call last):
File "C:\Users\Administrator.IP22\Envs\dell\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Administrator.IP22\Envs\dell\lib\site- packages\django\db\backends\oracle\base.py", line 497, in execute
return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.ProgrammingError: positional and named binds cannot be intermixed`

click here to see error screenshot

以下代码在settings.py中用于数据库

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.oracle',
    'NAME': 'orcl',
    'USER': 'C##',
    'PASSWORD': 'Oracle_1',
    'HOST': '',
    'PORT': '',
}
}

这是文件0002_remove_content_type_name.py的代码:

from django.db import migrations, models


def add_legacy_name(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
for ct in ContentType.objects.all():
    try:
        ct.name = apps.get_model(ct.app_label, ct.model)._meta.object_name
    except LookupError:
        ct.name = ct.model
    ct.save()


class Migration(migrations.Migration):

dependencies = [
    ('contenttypes', '0001_initial'),
]

operations = [
    migrations.AlterModelOptions(
        name='contenttype',
        options={'verbose_name': 'content type', 'verbose_name_plural': 'content types'},
    ),
    migrations.AlterField(
        model_name='contenttype',
        name='name',
        field=models.CharField(max_length=100, null=True),
    ),
    migrations.RunPython(
        migrations.RunPython.noop,
        add_legacy_name,
        hints={'model_name': 'contenttype'},
    ),
    migrations.RemoveField(
        model_name='contenttype',
        name='name',
    ),
]

1 个答案:

答案 0 :(得分:0)

该问题归因于cx_Oracle 6.4中引入的bug。如果可以从源代码构建,则可以获取已修复该错误的最新代码。或者,您可以等到cx_Oracle 6.4.1发布(可能几天后)。