I need to replace the cell value in the database if it falls under the condition. I make such a request:

UPDATE oc_product_to_category SET category_id = 74 WHERE category_id = 68 OR category_id = 70 OR category_id = 69 OR category_id = 72 OR category_id = 73 OR category_id = 85 OR category_id = 84 OR category_id = 71 

I get the error specified in the header. How to fix?

  • one
    category_id - included in the expression of the primary key. Its (expression) value must be unique in each record (there is no other record with that value). And you want to make such duplicates of as many as 8 pieces - the stump server is clear resists ... - Akina
  • category_id is not a primary key there. Primary key there product_id prntscr.com/mrtdub - Lichtgestalt
  • Yes, guys! primary key composite - (product_id, category_id). Those. unique must be a couple of fields. Those. ALREADY there is an entry with product_id = 235 and category_id = 74, and you want to change the entry with product_id = 235 and category_id = 68 (or another category_id from the list). Alternatively - there are at least 2 entries with product_id = 235 and category_id from the list. This will lead to duplication of the primary key expression (the values ​​of this pair of fields). Ps. And instead of screenshots, polite people show CREATE TABLE in text form. - Akina
  • @Akina Everything - looked at the table - understood. And you can somehow rewrite the request so that if for example after replacing the key will be duplicated then delete the string? - Lichtgestalt
  • @Lichtgestalt Doubt. Check and delete everything before, and then do the update. - iluxa1810

0