[Django]-Django: MySQL syntax error when passing parameters to raw SQL query

4👍

I think you can only pass query parameters, not field names, so it will not work for table names.

Alternatively, you can try simple string building for your query:

test_query = 'SELECT * FROM %s' % 'polls_poll'
test = Poll.objects.raw(test_query)

Although, string formatting for raw queries is not recommended.

More information: https://docs.djangoproject.com/en/dev/topics/db/sql/#passing-parameters-into-raw

Leave a comment