【发布时间】:2018-12-14 23:22:47
【问题描述】:
我在将 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',
),
]
【问题讨论】:
-
您的连接正常。在执行查询期间引发错误。看看 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