我遇到了问题,每当我尝试运行下面的代码并选择语句 2 以插入工具 并输入随机工具名称时,我都会收到错误消息:ProgrammingError ('column "inserttool' does not exist\nLine 1: insert tools(tool_name, rental_days) values(@insertTool, '2') .
代码如下:
if Menu == "2":
cursor = connection.cursor()
InsertTool = raw_input("Please insert the tool that you want to add.\n")
insert_tool = """insert into tools(tool_name, rental_days) values(@InsertTool, '2')"""
try:
cursor.execute( insert_tool);
connection.commit();
print("Tool is succesfully inserted!")
except Exception as e:
connection.rollback();
print("Exception Occured : ",e)
connection.close();
最佳答案
试试这个。
if Menu == "2":
cursor = connection.cursor()
InsertTool = raw_input("Please insert the tool that you want to add.\n")
insert_tool = """insert into tools(tool_name, rental_days) values(%s, %s)"""
val = (InsertTool, "2")
try:
cursor.execute(insert_tool, val);
connection.commit();
print("Tool is succesfully inserted!")
except Exception as e:
connection.rollback();
print("Exception Occured : ",e)
connection.close();
关于postgresql - 尝试将用户的输入插入 SQL 表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59099440/