我的Python代码在更新MySQL表时ID =整数的错误是什么?

时间:2014-06-25 14:04:42

标签: python mysql mysql-python

>>> print x 
 [(1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (10,)]

>>> for i in range(10):
...     if len(x)>0:
...             m = random.choice(x)
...             x.remove(m)
...             y = "%s" %m
...             z = int(y)
...             cur.execute("""UPDATE accounts SET column = 'YES' WHERE userid = %s""", (z, ))

但这并没有做任何事情。当我查看帐户表时,没有任何改变。

1 个答案:

答案 0 :(得分:3)

您需要在更新后提交更改:

db.commit()

其中db是数据库连接实例(connect()调用的结果)。

另见:Database does not update automatically with MySQL and Python