Answers.Body: <p>If CiviCRM is the <em>only</em> module installed, consider upgrading to the current release if at all possible.</p>
  
  <p>Doing this is likely to fix a lot of bugs, and may well address your problem. It will also address multiple security issues fixed between 4.5.5 and the current release, which is probably just as important to you and your contacts. We strongly recommend keeping up to date with a supported CiviCRM release.</p>
  
  <p>If you have a compelling reason to stick with 4.5.5, then consider the workaround in my other answer.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-10T07:55:19.350Z
Answers.LastActivityDate: 2015-09-10T07:55:19.350Z
Answers.UserDisplayName: Chris Burgess
Answers.Body: <p>Looks very similar to the error message I got after upgrading to 4.6.8 which was affecting every Drupal module or CiviCRM extension I tried to install. </p>
  
  <p>Reproduce the same conditions in order to reproduce the error and then look at the day's log file in sites/default/files/civicrm/ConfigAndLog This might give you some clue what was the cause. </p>
  
  <p><a href="https://civicrm.stackexchange.com/questions/6276/civix-install-error-api-error-db-error-already-exists">In my case</a> it was choking on pre-installed and unwanted demo Cases. After disabling them I got things running error free again. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-10T10:14:07.923Z
Answers.LastActivityDate: 2015-09-10T10:14:07.923Z
Answers.UserDisplayName: ñull
Answers.Body: <p>I've had the same issue on 4.6.8.
  Couldn't install any Drupal modules after creating a custom CiviCRM case type.
  Getting the same Drupal log error as seen above (Exception: API error: DB Error: already exists in CRM_Core_ManagedEntities->onApiError() (line ...).</p>
  
  <p>Disabling the case type allows the Drupal modules to be installed.</p>
  
  <p>Olly</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-06T09:29:46.573Z
Answers.LastActivityDate: 2015-10-06T09:29:46.573Z
Answers.UserDisplayName: Oliver Gibson
Answers.Body: <p>After looking at "sites/default/files/civicrm/ConfigAndLog", I have found that disabled "Relationship Type" under "Administer/Customize Data and Screens/Relationship Type/" was causing the error. After deleting relationship, error was gone.</p>
  
  <p>version 4.6.15</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-30T04:24:56.140Z
Answers.LastActivityDate: 2016-04-30T04:24:56.140Z
Answers.UserDisplayName: Dave
Answers.Body: <p>It looks like CiviCRM is trying to insert some "Managed Entities" which already exist in the DB. Certain actions within the Drupal CMS will trigger CiviCRM to attempt this, and enabling / disabling modules is one of them.</p>
  
  <p>What I might do in this situation (if I had to fix it without upgrading CiviCRM) is:</p>
  
  <ul>
  <li>Make a backup of your DB. Make two.</li>
  <li>Look in CiviCRM's debug logfile for <code>ManagedEntities_failed</code> - this has additional information to the Exception message you posted above.</li>
  <li>Review the entry which CiviCRM was unable to insert to the DB (because a conflicting entry already existed).</li>
  <li>If the entry CiviCRM tried to insert matches closely to an entry in the DB, then remove the DB entry you find and hope that when CiviCRM re-inserts the same, it "sticks" the second time around.</li>
  <li>You might need to repeat this process, so pay attention to any new errors in the same logfile, and see if they are clashing with new entries or the same one ...</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-17T01:13:54.987Z
Answers.Text: The logfile revealed that it was trying to add one of the built-in relationship types - we had deleted four of them via the UI in order to simplify things, but they were still in the database.
Answers.UserDisplayName: Richard Grevers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-10T07:53:06.107Z
Answers.LastActivityDate: 2015-09-10T07:53:06.107Z
Answers.UserDisplayName: Chris Burgess
Body: <p>Drupal version 7.34, CiviCRM version 4.5.5</p>
  
  <p>Hi,
  When I try to install Views and CTools on our Intranet installation, I am getting the following error from Drupal:</p>
  
  <p>Exception: API error: DB Error: already exists in CRM_Core_ManagedEntities->onApiError() (line 396 of /srv/www/htdocs/drupal/sites/all/modules/civicrm/CRM/Core/ManagedEntities.php)</p>
  
  <p>(currently, CIviCRM is the only module installed)</p>
  
  <p>Is this something that upgrading both CiviCRM and Drupal will fix?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-10T02:25:18.617Z
Comments.Text: I've previously asked this on the Drupal community, without any response.
Comments.UserDisplayName: Richard Grevers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-10T02:59:29.717Z
Comments.Text: Not sure what the underlying issue here is, but the fact that CiviCRM tries to fire various hooks when unrelated Drupal modules are enabled is a reported issue: [CRM-13796: Don't CRM_Core_Invoke::rebuildMenuAndCaches(TRUE) on every Drupal module enable / disable](https://issues.civicrm.org/jira/browse/CRM-13796). You may need to debug what API action CiviCRM is choking on for your site, though; there is advice elsewhere on how to debug exceptions & errors within CiviCRM.
Comments.UserDisplayName: Chris Burgess
Tags: <drupal><drupal-views>
Title: Error from CiviCRM code when I try to install other Drupal modules
ThreadText: # Error from CiviCRM code when I try to install other Drupal modules
  
  (Asked by: username_0 on 2015-09-10)
  
  Drupal version 7.34, CiviCRM version 4.5.5
  
  Hi,
  When I try to install Views and CTools on our Intranet installation, I am getting the following error from Drupal:
  
  Exception: API error: DB Error: already exists in CRM\_Core\_ManagedEntities->onApiError() (line 396 of /srv/www/htdocs/drupal/sites/all/modules/civicrm/CRM/Core/ManagedEntities.php)
  
  (currently, CIviCRM is the only module installed)
  
  Is this something that upgrading both CiviCRM and Drupal will fix?
  
  **Tags:** drupal, drupal-views
  
  > **Comments:**
  > **username_0**: I've previously asked this on the Drupal community, without any response.  
  > **username_1**: Not sure what the underlying issue here is, but the fact that CiviCRM tries to fire various hooks when unrelated Drupal modules are enabled is a reported issue: [CRM-13796: Don't CRM_Core_Invoke::rebuildMenuAndCaches(TRUE) on every Drupal module enable / disable](https://issues.civicrm.org/jira/browse/CRM-13796). You may need to debug what API action CiviCRM is choking on for your site, though; there is advice elsewhere on how to debug exceptions & errors within CiviCRM.  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_1 on 2015-09-10. Score: 5 | Accepted answer
  
  It looks like CiviCRM is trying to insert some "Managed Entities" which already exist in the DB. Certain actions within the Drupal CMS will trigger CiviCRM to attempt this, and enabling / disabling modules is one of them.
  
  What I might do in this situation (if I had to fix it without upgrading CiviCRM) is:
  
  * Make a backup of your DB. Make two.
  * Look in CiviCRM's debug logfile for `ManagedEntities_failed` - this has additional information to the Exception message you posted above.
  * Review the entry which CiviCRM was unable to insert to the DB (because a conflicting entry already existed).
  * If the entry CiviCRM tried to insert matches closely to an entry in the DB, then remove the DB entry you find and hope that when CiviCRM re-inserts the same, it "sticks" the second time around.
  * You might need to repeat this process, so pay attention to any new errors in the same logfile, and see if they are clashing with new entries or the same one ...
  
  > **Comments:**
  > **username_0**: The logfile revealed that it was trying to add one of the built-in relationship types - we had deleted four of them via the UI in order to simplify things, but they were still in the database.  
  
  ---
  
  ### Answer by username_1 on 2015-09-10. Score: 2
  
  If CiviCRM is the *only* module installed, consider upgrading to the current release if at all possible.
  
  Doing this is likely to fix a lot of bugs, and may well address your problem. It will also address multiple security issues fixed between 4.5.5 and the current release, which is probably just as important to you and your contacts. We strongly recommend keeping up to date with a supported CiviCRM release.
  
  If you have a compelling reason to stick with 4.5.5, then consider the workaround in my other answer.
  
  
  ---
  
  ### Answer by username_2 on 2015-09-10. Score: 2
  
  Looks very similar to the error message I got after upgrading to 4.6.8 which was affecting every Drupal module or CiviCRM extension I tried to install.
  
  Reproduce the same conditions in order to reproduce the error and then look at the day's log file in sites/default/files/civicrm/ConfigAndLog This might give you some clue what was the cause.
  
  [In my case](https://civicrm.stackexchange.com/questions/6276/civix-install-error-api-error-db-error-already-exists) it was choking on pre-installed and unwanted demo Cases. After disabling them I got things running error free again.
  
  
  ---
  
  ### Answer by username_3 on 2015-10-06. Score: 2
  
  I've had the same issue on 4.6.8.
  Couldn't install any Drupal modules after creating a custom CiviCRM case type.
  Getting the same Drupal log error as seen above (Exception: API error: DB Error: already exists in CRM\_Core\_ManagedEntities->onApiError() (line ...).
  
  Disabling the case type allows the Drupal modules to be installed.
  
  Olly
  
  
  ---
  
  ### Answer by username_4 on 2016-04-30. Score: 0
  
  After looking at "sites/default/files/civicrm/ConfigAndLog", I have found that disabled "Relationship Type" under "Administer/Customize Data and Screens/Relationship Type/" was causing the error. After deleting relationship, error was gone.
  
  version 4.6.15
  
  
  ---
  
  