3
我剛剛找到了用於將Python連接到MySQL數據庫的pymysql模塊。我有一個名爲'loot'的表建立了數據庫,loot包含一個名爲'wins'的列。我的代碼包含一個名爲'won'的變量,在SQL行之前給出一個值。我希望將變量'won'輸入到id = 1的'wins'列中。數據庫中已存在id = 1行。下面Python 3更新MySQL數據庫表
的代碼拋出錯誤pymysql.err.InternalError: (1054, "Unknown column 'won' in 'field list'")
我的問題:爲什麼會出現這個錯誤,我在做什麼錯誤?
驗證碼:
import pymysql
# Open database connection
db = pymysql.connect(host='*******',user='******',password='*****',db='******')
# prepare a cursor object using cursor() method
cursor = db.cursor()
won=1
# Prepare SQL query to UPDATE required records
sql = "UPDATE loot SET wins = won WHERE id = 1"
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
# disconnect from server
db.close()
即時通訊仍在學習:-)這實際上是一個元組內的元組? – Brandon
這是一個方法調用中的元組。 – bernie
我們都在學習,順便說一下:-) – bernie