Hello everyone,
I am re-studying the Becoming a Reactive Web Developer Guided Path and while I was doing the demo to create a unique index, this error appears:
"Could not create unique index on 'ORDERID,PRODUCTID' of entity 'OrderProduct'. It has duplicate values."
I just downloaded and open the modules on Service Studio. Is there a way for me correct this so I can complete the demo?
Do I need to find the duplicate values on each entity in question and delete/modify them?
Thank you
Hi Hugo,
As you have rightly pointed out, the issue is thrown as your OrderProduct entity has multiple records with the same OrderId,ProductId combination so unable to add unique index.
You can write logic to delete the duplicate entries and then retry setting unique index.
Below is a query which you can try in AdvanceSQL element to get the duplicated data deleted, and run in a screen/server action.
DELETE FROM {OrderProduct} WHERE {OrderProduct }.[Id] NOT IN
(SELECT MAX({OrderProduct }.[Id]) FROM {OrderProduct} GROUP BY {OrderProduct}.[OrderId], {OrderProduct}.[ProductId] );
Do consider to initially run the Select carry individually using AdvanceSQL element to ensure that it is providing correct results.
Hope this helps.
Regards,
Saurabh