我只想使用UPDATE命令进行刷新。这给出了错误,我该在哪里出错?

for checkNewAbility in list(newAbilities1):
    if not checkNewAbility in list(oldAbility[1]):
        my_cursor.execute(
           "UPDATE mydb.skill SET skill_name='%s' WHERE Person_person_id='%s'
                AND skill_id='%d';",(checkNewAbility, url[0], oldAbility[0]))
        realdb.commit()


错误:


  “处理格式参数失败;%s”%err)
  mysql.connector.errors.ProgrammingError:处理失败
  格式参数; Python'tuple'无法转换为MySQL类型


我的清单有:


  oldAbility = [(43,'PHP'),(44,'HTML'),(45,'CSS')]
  
  newAbilities1 = ['Java','Python','JavaScript']
  
  我只想根据id用newAbilities1替换oldAbilities。

最佳答案

如果您正确地复制并粘贴了代码,那么执行(之后将缺少双引号“”。我假设您使用的是pyodbc。

for checkNewAbility in list(newAbilities1):
    if not checkNewAbility in list(oldAbility[1]):
        my_cursor.execute("UPDATE mydb.skill SET skill_name='?' WHERE Person_person_id='?' AND skill_id='?'", (checkNewAbility, url[0], oldAbility[0]))
        realdb.commit()

关于python - 我怎么不得到mysql转换元组错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55761158/

10-12 17:50