0

Magento 2.x throws an error message on saving a product that has a unique, required attribute value when that value has been used before by a product that has been deleted.
In other words: the attribute's unique value of a product, remains stored in the database after that product has been deleted.

EXAMPLE
Say we create a product in M2 admin.

  1. We have a REQUIRED Custom Attribute "SKU Number" with UNIQUE value "1".
  2. Save the product and than delete the product and flush cache.
  3. Create new product in M2 admin.
  4. Apply required Custom Attribute "SKU Number". Also with value "1" (from deleted product).

It appears that we are now unable to save this newly created product because it uses the unique value of a deleted product. Error message: "Required attribute value must be unique".

IMHO the attribute value in this case is unique because the product that has been using this unique value has been deleted.

Does anybody have an idea about how can I delete the unique value of a custom attribute when it is no longer in use by a product?

  • Did you try reindexing your catalog data? – Jaimin Sutariya Jan 29 '18 at 18:01
  • @Jaimin If you mean reindex all indexers: Yes, I did. Even from the CLI. – Els den Iep Jan 29 '18 at 20:11
  • Not a solution but might be a quick workaround: try to remove that attribute option that has been in use earlier and add the same option then again. As per your description this sounds somewhat unwanted (even though one may call it a feature rather than a bug). However, how did you delete the product? – Christoph Farnleitner Jan 30 '18 at 1:44
  • @ChristophFarnleitner: Somewhat unwanted indeed. Deleted the product from Catalog in admin interface. I don't know of a different way to delete a product. As for the attribute: I have set the requiered unique attribute to "not requiered" and "not unique", flushed cache, reindexed, and set it back to "requiered" and "unique", but it does not work. Does it work on your side? – Els den Iep Jan 31 '18 at 11:01
  • @ElsdenIep, I meant to delete the attribute option - i.e. if you to an attribute "color" and have unique options as "red", "green", "blue" and you can not use "blue" anymore due to deleting that product, you may try to delete the option "blue" from the attribute, save it and re-add it. (no, not tested, just an idea on how to work around the described issue in backend only) – Christoph Farnleitner Jan 31 '18 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.