magento 2: Getting Error Unique constraint violation found – When remove suffix .html

  • Open
  • Shiwani
    Participant
    August 14, 2019 at 12:49 pm #2577
    Shiwani

    Hi All

    I Am getting error when I am removing .html from Category URL Suffix. Error is Unique constraint violation found.

    Anyone have genuine solution for this.

    Thanks

  1. Pankaj Sharma
    Participant
    Posts: 154
    August 16, 2019 at 11:06 am #2596
    Pankaj Sharma

    Hi Shiwani,

    This issue can be due to the duplicate entries for the products and categories. If there are URLs already saved in url_rewrite table you need to remove these entries. You can check and remove entries from table url_rewrite.

    I hope it will work for you.

    Thanks

    • This reply was modified 10 months, 3 weeks ago by Pankaj Sharma Pankaj Sharma.
  2. AnonymousPosts: 1
    November 17, 2019 at 11:59 am #4186

    This can be caused by duplicate entries for the same product in url_rewrite database table.

    You can follow the below steps to solve this issue:

    Backup your current Magento2 database
    Delete all records from table url_rewrite. You can run the following SQL command:

    DELETE FROM url_rewrite WHERE entity_type = ‘product’;
    Login to your Magento 2 backend
    Re-save all your Categories

    or

     

    regenerate url_rewrites again by using this

    https://github.com/olegkoval/magento2-regenerate_url_rewrites

    Clean the Magento2 cache
    Now, you should be able to save/update the Product URL Suffix in the Configuration Settings.

     

    • AnonymousPosts: 2
      May 21, 2020 at 3:46 pm #5568

      regenerate url_rewrites again by using this

      https://github.com/olegkoval/magento2-regenerate_url_rewrites

      Clean the Magento2 cache
      Now, you should be able to save/update the Product URL Suffix in the Configuration Settings.

      I tried this and it did not resolve the issue. I cannot change the suffix in the Magento Admin. Unique constraint violation found
      Any other ideas?

      • AnonymousPosts: 2
        May 21, 2020 at 3:59 pm #5569

        Nevermind, I just removed the product and category records:

        DELETE FROM url_rewrite WHERE entity_type = ‘product’;
        DELETE FROM url_rewrite WHERE entity_type = ‘category’;

        Then I updated the configuration to remove the suffix and saved successfully.

        Then I reindexed:

        php bin/magento ok:urlrewrites:regenerate –entity-type=product
        php bin/magento ok:urlrewrites:regenerate –entity-type=category

  3. Pankaj Sharma
    Participant
    Posts: 154
    December 13, 2019 at 6:11 am #4501
    Pankaj Sharma

    Hello Sandeep,

    Thanks for the detailed information and your solution.