我在将 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',
),
]
答案 0 :(得分:0)
该问题归因于cx_Oracle 6.4中引入的bug。如果可以从源代码构建,则可以获取已修复该错误的最新代码。或者,您可以等到cx_Oracle 6.4.1发布(可能几天后)。