如何修复,更新条件不起作用
How to fix, where condition with update not working
我正在尝试使用 where 条件更新我的 table。我不确定我哪里错了。
我在 python 中使用 peewee 进行 SQL 查询。我正在尝试更新具有相同列的两个不同的 table。该查询在 table1 上运行良好,但在 table2 上运行不正常,尽管它们是相同的。最奇怪的是,没有任何错误。我还启用了查询日志记录。
if x:
for id in x:
table1.update(status = 0).where(table1.slab_id == id).execute()
table2.update(status = 0).where(table2.slab_id == id).execute()
预期:table1 和 table2 更新为状态 = 0,提供的 ID。
实际:table1 已成功更新,而 table2 的所有值都在更新,而不是只有一个。我还记录了如下查询:
('UPDATE `table1` SET `status` = %s WHERE (`table1`.`slab_id` = %s)', [0, 44])
('UPDATE `table1` SET `status` = %s WHERE (`table1`.`slab_id` = %s)', [0, 43])
('UPDATE `table2` SET `status` = %s', [0])
('UPDATE `table2` SET `status` = %s', [0])
'UPDATE `table2` SET `status` = 0 WHERE `table2`.`slab_id` = 43
-> 有效
对于未应用条件的 table2,我不明白为什么?
这可能是版本不匹配或外键约束的情况,不允许更新或删除 table。
我正在尝试使用 where 条件更新我的 table。我不确定我哪里错了。
我在 python 中使用 peewee 进行 SQL 查询。我正在尝试更新具有相同列的两个不同的 table。该查询在 table1 上运行良好,但在 table2 上运行不正常,尽管它们是相同的。最奇怪的是,没有任何错误。我还启用了查询日志记录。
if x:
for id in x:
table1.update(status = 0).where(table1.slab_id == id).execute()
table2.update(status = 0).where(table2.slab_id == id).execute()
预期:table1 和 table2 更新为状态 = 0,提供的 ID。 实际:table1 已成功更新,而 table2 的所有值都在更新,而不是只有一个。我还记录了如下查询:
('UPDATE `table1` SET `status` = %s WHERE (`table1`.`slab_id` = %s)', [0, 44])
('UPDATE `table1` SET `status` = %s WHERE (`table1`.`slab_id` = %s)', [0, 43])
('UPDATE `table2` SET `status` = %s', [0])
('UPDATE `table2` SET `status` = %s', [0])
'UPDATE `table2` SET `status` = 0 WHERE `table2`.`slab_id` = 43
-> 有效
对于未应用条件的 table2,我不明白为什么?
这可能是版本不匹配或外键约束的情况,不允许更新或删除 table。