'Api error: DB Error: already exists' on drush cc civicrm and any extension enable/disable
'Api error: DB Error: already exists' on drush cc civicrm and any extension enable/disable on a fairly new site.
On drush cc civicrm and any extension enable/disable.
CRM_Core_ManagedEntities::reconcile() is called and this method tries to re create a relationship-type that already exists.
On looking into more, it was an issue with core Case XMLProcessor. Case ManagedEntities checks all Case types and their XML definition and then checks to see if all relationship types used within the case types needs to be created/updated.
Here on checking the relatoinship types between case type XML definition and all relationship types, there is a mismatch in the field used to compare them. The "label_b_a" field is compared with "name_b_a" and so if these two are not the same (there is no need to be) it tries to re create it and results in this error.