Cannot insert duplicate key row in object

Yesterday when I was trying to import a solution I was getting this error:

Cannot insert duplicate key row in object ‘MetadataSchema.AttributeLookupValue’ with unique index ‘NDX_AttrLookupValAttrIdEntityIdCompState’. The duplicate key value is (3343d9f8-8b3b-45de-881f-4501a34e29de, 8, 0, fd140aae-4df4-11dd-bd17-0019b9312238, Jan 1 1900 12:00AM) the statement has been terminated.

After some digging and doing some queries on SQL, I was able to identify the field that was giving me the problem. Some search on the web and I found these posts that helped me:

  • In this one it helped on querying the DB in SQL to know the field:
  • In this post, it also says a way to remove the duplicate key row, but it is specific to that case, make sure to have a backup and perform this operation in an isolated environment.

  • In this post I found a way to go around the problem but not solving it:
  • Comment (or remove) the field that is giving the error in the solution and then zips it again and import.

    Removing the field from the solution allowed completing the import.

    Hope this helps!