mysql:
cursor = connection.cursor()
cursor.execute('''
UPDATE models_buy SET remain_quantity = %s
where id = %s''',[one['remain_quantity'], one['id']]
)
cursor.execute("commit")
在数据库中我的id、remain_quantity字段是float型,但是数据库中只能%s,我想用%d报错了。先这样,项目完结再研究!还有注意的是update完要commit
user = 'remain_quantity'
string = 'UPDATE models_buy SET ' + user + ' = ' + user+ ' + 111 ' + 'where id = 1'
cursor.execute(string)
cursor.execute("commit") cursor.execute('''
UPDATE models_buy SET {}={} + 1 where id = 1'''.format(user,user)
)
cursor.execute("commit")