简体   繁体   English

如何解决,更新无效的条件

[英]How to fix, where condition with update not working

I am trying to update my table using where condition. 我正在尝试使用where条件更新我的表。 I am not sure where I am going wrong. 我不确定我哪里出错了。

I am using peewee for SQL queries in python. 我在python中使用peewee进行SQL查询。 I am trying to update two different tables having the same column. 我正在尝试更新具有相同列的两个不同的表。 The query is working fine with table1 but not with table2, though they both are same. 查询在table1中工作正常但与table2不兼容,尽管它们都是相同的。 And the most strange part, there are no errors. 而最奇怪的部分,没有错误。 I also enabled query logging. 我还启用了查询日志记录。

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()

expected: table1 and table2 to be updated with status = 0, for provided id. expect:table1和table2将更新为status = 0,用于提供的id。 actual: table1 is successfully updated, while all values of table2 are getting updated instead of only one. actual:table1已成功更新,而table2的所有值都已更新,而不是只有一个。 I also logged the query they are as follows: 我还记录了他们的查询如下:

('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 -> works 'UPDATE `table2` SET `status` = 0 WHERE `table2`.`slab_id` = 43 - > works

For table2 where a condition is not applied, I am failing to understand why? 对于没有应用条件的table2,我不明白为什么?

这可能是版本不匹配或外键约束的情况,它不允许更新或删除表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM