【问题标题】:Unable to connect Django 2.0.7 with oracle 12c using cx_oracle 6.4 in python 3.7无法在 python 3.7 中使用 cx_oracle 6.4 将 Django 2.0.7 与 oracle 12c 连接
【发布时间】:2018-12-14 23:22:47
【问题描述】:

我在将 Orace 12cDjango 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',
    ),
]

【问题讨论】:

  • 您的连接正常。在执行查询期间引发错误。看看 contenttypes.0002_remove-content_type_name 迁移是什么样子会很有趣
  • 好像有bug in cx_oracle introduced in 6.4。显然,这在 6.3.1 中不存在,因此降级可能是一种选择。或者,等待 6.4.1
  • 我在我的帖子中添加了文件 0002_remove_content_type_name.py 代码
  • 谢谢,但我真的认为问题在于我在第二条评论中链接的提到的 cx_Oracle 6.4 错误。您是否可以降级到 cx_Oracle 6.3.1 并尝试使用该版本?

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


【解决方案1】:

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

【讨论】:

  • Anthony 发布了 cx_Oracle 6.4.1。
猜你喜欢
  • 2021-08-06
  • 2018-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-06
  • 2019-12-27
相关资源
最近更新 更多