[Django]-Django cursor.executemany parameters

3👍

When I only replace the ? with %s it works as expected.

The ? placeholder is used for SQLite only:

Put ? as a placeholder wherever you want to use a value, and then provide a tuple of values as the second argument to the cursor’s execute() method. (Other database modules may use a different placeholder, such as %s or :1.)

MySQL drivers expect to see %s as a query parameter placeholder:

query = "REPLACE INTO names (id, name) VALUES (%s, %s)"
cursor.executemany(query, values)

Another thing (that got me started searching) is that PyCharm is giving me an error when using %s.

PyCharm does not issue any warnings on my end. You’ve probably did something different:

enter image description here

👤alecxe

Leave a comment