Skip to content Skip to sidebar Skip to footer

No Such Column Error In Python

db = sqlite3.connect('SQL database') cursor = db.cursor() query = 'DELETE FROM Item WHERE ItemID = {}'.format(self.ID) cursor.execute(query) db.commit() cur

Solution 1:

Your query looks like:

DELETEFROM Item WHERE ItemID = hello

The error message is helpful in this case.

Instead do:

db = sqlite3.connect("SQL database")
cursor = db.cursor()
query = 'DELETE FROM Item WHERE ItemID = ?'
cursor.execute(query, (self.ID,))
db.commit()
cursor.close()

Notes:

  1. The parameter placeholder for sqlite3 is ?.
  2. The parameter value should be the second argument to .execute()
  3. That parameter should be passed to .execute() as a sequence. A tuple is fine.

Post a Comment for "No Such Column Error In Python"