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:
- The parameter placeholder for sqlite3 is
?
. - The parameter value should be the second argument to
.execute()
- That parameter should be passed to
.execute()
as a sequence. A tuple is fine.
Post a Comment for "No Such Column Error In Python"