I'm having trouble updating my stock table using a stored procedure in MYSQL. Here is the code:
CREATE DEFINER='root'@'localhost' PROCEDURE 'atualiza_estoque'(id_produto int)
BEGIN
update estoque e inner join reposicao r on r.produto = e.produto
set e.qtd = if (e.qtd = 0, r.qtd, e.qtd+r.qtd), e.data_entrada = now()
where e.produto = id_produto and r.produto=id_produto and r.data_reposicao > e.data_entrada;
END
When calling the procedure call atualiza_estoque(1);
, the error message is displayed
Error Code: 1175. You are using safe update mode and you tried to update a table without WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences - > SQL Editor and reconnect.
The funny thing is that I was able to run the procedure twice before this message appeared. What was causing this error? I tried to pass the stock id as a parameter, but the same message appears.
Note: I know that it is possible to disable safe update, but I would like to understand what is causing this error, and the procedure worked perfectly twice before presenting the error.