当前位置: 动力学知识库 > 问答 > 编程问答 >

Error while using date between in django raw query

问题描述:

I am always getting this error TypeError: not all arguments converted during string formatting

Here is my query

State.objects.raw('...review_create_date between %s and %s group by error_type',[fromdate,todate])

Here fromdate=2011-05-21 and todate='2011-05-27'

The above query executes in mysql prompt but could not able to run in python shell

Please some one help me

Here is the traceback

 Traceback (most recent call last):

File "<console>", line 1, in <module>

File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 1412, in __iter__

query = iter(self.query)

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 73, in __iter__

self._execute_query()

File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 87, in _execute_query

self.cursor.execute(self.sql, self.params)

File "/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py", line 18, in execute

sql = self.db.ops.last_executed_query(self.cursor, sql, params)

File "/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 216, in last_executed_query

return smart_unicode(sql) % u_params

TypeError: not all arguments converted during string formatting

网友答案:

Try using ? instead of %s.

分享给朋友:
您可能感兴趣的文章:
随机阅读: