[英]mysql #1054 - Unknown column in 'where clause' when update, but can be selected
I'm quite confused with this problem.我对这个问题很困惑。
I have a table of purchase_list
that about like this:我有一个
purchase_list
表,大概是这样的:
purchase_code item unit order_amount recived_amount price
TRX-000001 1 1 0 85 14200
Then i try to update that record with this query:然后我尝试使用此查询更新该记录:
UPDATE `purchase_list`
SET `order_amount`='85'
WHERE `purchase_code`='TRX-000001' AND `item`='1' AND `unit`='1'
And end up with error:并最终出现错误:
#1054 - Unknown column 'unit' in 'where clause'
But when i do SELECT
query:但是当我做
SELECT
查询时:
SELECT `order_amount`
FROM `purchase_list`
WHERE `purchase_code`='TRX-000001' AND `item`='1' AND `unit`='1'
it does show result:它确实显示了结果:
order_amount
0
And when I click phpmyadmin's Simulate query
button, it does says:当我单击 phpmyadmin 的
Simulate query
按钮时,它确实说:
Matched rows: 1
but still it can't execute the update query.但它仍然无法执行更新查询。 Any idea how to solve my problem?
知道如何解决我的问题吗?
Check datatype of unit
column and try with检查
unit
列的数据类型并尝试
AND `unit`=1
If data type of unit
is int else share table structure of `purchase_list.如果
unit
数据类型是int,则共享`purchase_list的表结构。
The most likely cause of your problem is a trigger on purchase_list
.您的问题最可能的原因是
purchase_list
上的触发器。 You should check if that is the case.您应该检查是否是这种情况。
A secondary possibility is that the two queries are pointing to different databases with different table structures.第二种可能性是这两个查询指向具有不同表结构的不同数据库。
Sometimes this error occurs due to the use of same quotes (single ' or double ") for column name and value. For example, in my case: I used these two queries有时会发生此错误是由于对列名和值使用了相同的引号(单 ' 或双 ")。例如,在我的情况下:我使用了这两个查询
Query #1:查询#1:
UPDATE 'customerinvoice'
SET 'invoice_status' = 2
WHERE 'invoice_no' = '20200907202602_6'
Query #2:查询#2:
'UPDATE customerinvoice
SET invoice_status = 2
WHERE invoice_no = 20200907202602_6'
and it throws this error.它会抛出这个错误。
(1054, "Unknown column '20200907202602_6' in 'where clause'")
(1054,“'where 子句'中的未知列'20200907202602_6'”)
I solved this issue using:我使用以下方法解决了这个问题:
Query #1查询#1
UPDATE 'customerinvoice'
SET 'invoice_status' = 2
WHERE 'invoice_no' = "20200907202602_6"
Query #2:查询#2:
'UPDATE customerinvoice
SET invoice_status = 2
WHERE invoice_no = "20200907202602_6" '
Note: I am working in python and database is MySQL.注意:我在 python 中工作,数据库是 MySQL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.