mysql: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

Trabla: mysql: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

Solving:

Example
table "my_user" : id PRIMARY KEY, "name" varchar, "email" varchar, "token" varchar

Query:
UPDATE my_user SET token = '-1' WHERE token IS NULL or token = '';
Will throw:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column

Fixing - add in where condition with primary key:
UPDATE my_user SET token = '-1' WHERE (token IS NULL or token = '') AND id > 0;

No comments:

Post a Comment