django.db.utils.ProgrammingError: not enough arguments for format string
django使用raw执行sql语句时报错
django.db.utils.ProgrammingError: not enough arguments for format string
sql语句
data = gsm.NodeMessage.objects.raw(
"""select * from node where 1=1 and channel_name like '%新局%' ORDER BY device_code, channel_code, `order` asc""".format(conditions)
)
原因
sql语句中含有“%”,这个“%”造成python认为此字符串有format倾向,出现错误。
解决方法
使用%%取代%可以解决这个问题
更正后:
sql语句
data = gsm.NodeMessage.objects.raw(
"""select * from node where 1=1 and channel_name like '%%新局%%' ORDER BY device_code, channel_code, `order` asc""".format(conditions)
)
后记
【后记】为了让大家能够轻松学编程,我创建了一个公众号【轻松学编程】,里面有让你快速学会编程的文章,当然也有一些干货提高你的编程水平,也有一些编程项目适合做一些课程设计等课题。
也可加我微信【1257309054】,拉你进群,大家一起交流学习。
如果文章对您有帮助,请我喝杯咖啡吧!
公众号
关注我,我们一起成长~~
还没有评论,来说两句吧...