在这行代码上我需要帮助。我想选择一行并将其从表中以及从数据库中删除。
def deleteProduct(self):
row = self.products_table.currentRow()
if row > -1:
currentproductid = (self.products_table.item(row, 0).text(), )
query = session.query(Product).filter(Product.product_id==currentproductid).first()
session.delete(query)
session.commit()
self.mainTable.removeRow(currentRow)
我收到此错误:
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 509, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.InterfaceError: <exception str() failed>
答案 0 :(得分:0)
def deleteProduct(self):
row = self.products_table.currentRow()
currentproductid = (self.products_table.item(row, 0).text() )
product_name = (self.products_table.item(row, 1).text() )
query = session.query(Product).filter(Product.product_id==str(currentproductid)).first()
session.delete(query)
session.commit()
self.products_table.removeRow(row)