[Solved]-Django Raw SQL give me TypeError not enough arguments

29👍

The raw SQL is a string with formatting parameters, which means that % indicates a parameter to format. Your string has % in it. You need to double them to protect them from interpretation:

diary = models.SablogArticles.objects.raw("""
    SELECT 
        articleid, 
        DATE_FORMAT(from_unixtime(dateline),'%%Y-%%m') as newtime,
        count(*) as howmany
    FROM sablog_articles group by newtime
    """)

Leave a comment