I\'m getting this error using sqlite3 in django:
Exception Value: too many SQL variables
And I think the answer to it is this, from
I had a similar problem, but when deleting just single row that had a large number of related rows in another table. Django was calling a cascading delete causing the problem, but since my code was only calling a single object delete, the solutions described in other answers could not be applied (unless I modified the Django library code, which I didn't want to do).
My solution was to first delete the related objects via raw sql query, then use the normal Django delete() on the parent object, all wrapped in a transaction.
Before:
object.delete() # Django tries to delete a large number of related object and fails
After:
from django.db import connection
Class MyObject:
def delete_related(self):
cur = connection.cursor()
sql = 'delete from my_table where ...'
cur.execute(sql, params)
...
with transaction.atomic():
object.delete_related() # so that Django won't try (and fail) on its own
object.delete()