我正在Windows 10上测试我的代码。我有一个Django应用程序,需要调用远程Server数据库上的存储过程。下面是来自settings.py的数据库片段:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db1',
'HOST': 'mycompany.com',
'PORT': '3306',
'USER': 'user',
'PASSWORD': 'pw',
},
'ss': {
'ENGINE': 'django_pyodbc',
'NAME': 'db2',
'HOST': 'myserver\SQLEXPRESS',
'USER': 'myuser',
'PASSWORD': 'mypw',
'PORT': '1433',
# 'DRIVER': 'SQL Server',
'OPTIONS': {
'driver_supports_utf8': True,
'host_is_server': True, # must be True for remote db
'autocommit': True,
'unicode_results': True,
'extra_params': 'tds_version=8.0',
},
},}
下面是我所看到的代码片段:
cursor = connections['ss'].cursor()
cursor.execute("{call dbo.mysproc(?)}", (id))当我执行cursor.execute语句时,会得到以下错误:
django.db.utils.DatabaseError:(“SQL包含1个参数标记,但提供了36个参数”、“HY000”)
我的参数id是GUID。有什么想法?
发布于 2017-05-12 23:05:15
下面是修复,只需将参数周围的括号更改为方括号:
cursor.execute("{call dbo.mysproc(?)}", [id])我是经过反复试验才发现这个的。
https://stackoverflow.com/questions/43921351
复制相似问题