Answers.Body: <p>this looks like some custom code you have setup which is passing through the wrong group id. Its indicated by the API identifier in the failure. I would check what custom code you have and establish where group 13 is being passed in, you could turn on the backtrace recording so that the exact source can be determined.</p>
  
  <p>The other thing to check is that the contribution page is set correctly in the section where contacts are automatically added to groups. Someone may have set it there and subsequently removed the group.</p>
  
  <p>Either may cause this issue.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-31T11:01:20.567Z
Answers.Text: I have found that group 13 exists but was not enabled. It is now deleted.
Answers.UserDisplayName: gsvadmin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-31T11:02:58.330Z
Answers.Text: By turn on the backtrace do you mean turn on debugging?
Answers.UserDisplayName: gsvadmin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-27T14:31:21.650Z
Answers.Text: @gsvadmin - If you go to **Administer menu » System Settings » Debugging and Error Handling**, you'll see there is a separate option for enabling backtraces in addition to enabling debugging.  Turning on both is essential for troubleshooting issues like this.  If you update your question with a backtrace in addition to what you provided, it's likely someone could better point out the nature of your problem.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-30T12:08:17.403Z
Answers.LastActivityDate: 2016-08-30T12:08:17.403Z
Answers.UserDisplayName: Parvez Saleh
Body: <p>In the following from the ConfigandLog, log, the value of group_id is given as 13 when it should be 9. In civicrm_groups there is NO 13 but in civicrm_custom_group there is.</p>
  
  <p>Aug 29 20:25:14  [info] $Fatal Error Details = Array
  (
      [callback] => Array
          (
              [0] => CRM_Core_Error
              [1] => exceptionHandler
          )</p>
  
  <pre><code>[code] =&gt; -3
  [message] =&gt; DB Error: constraint violation
  [mode] =&gt; 16
  [debug_info] =&gt; INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 4405 ,  13 ,  20160829202514 , 'API' , 'Removed' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gsv10274_04`.`civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]
  [type] =&gt; DB_Error
  [user_info] =&gt; INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 4405 ,  13 ,  20160829202514 , 'API' , 'Removed' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gsv10274_04`.`civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]
  [to_string] =&gt; [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::exceptionHandler prefix="" info="INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 4405 ,  13 ,  20160829202514 , 'API' , 'Removed' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gsv10274_04`.`civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]"]
  </code></pre>
  
  <p>)</p>
  
  <p>Why is Civi using the wrong group ID?
  Is this causing the fatal error?</p>
  
Tags: <civicontribute>
Title: DB Error: constraint violation when a member renews online
ThreadText: # DB Error: constraint violation when a member renews online
  
  (Asked by: username_0 on 2016-08-30)
  
  In the following from the ConfigandLog, log, the value of group\_id is given as 13 when it should be 9. In civicrm\_groups there is NO 13 but in civicrm\_custom\_group there is.
  
  Aug 29 20:25:14 [info] $Fatal Error Details = Array
  (
  [callback] => Array
  (
  [0] => CRM\_Core\_Error
  [1] => exceptionHandler
  )
  
  ```
  [code] => -3
  [message] => DB Error: constraint violation
  [mode] => 16
  [debug_info] => INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 4405 ,  13 ,  20160829202514 , 'API' , 'Removed' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gsv10274_04`.`civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]
  [type] => DB_Error
  [user_info] => INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 4405 ,  13 ,  20160829202514 , 'API' , 'Removed' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gsv10274_04`.`civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]
  [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::exceptionHandler prefix="" info="INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 4405 ,  13 ,  20160829202514 , 'API' , 'Removed' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gsv10274_04`.`civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]"]
  
  ```
  
  )
  
  Why is Civi using the wrong group ID?
  Is this causing the fatal error?
  
  **Tags:** civicontribute
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-30. Score: 1
  
  this looks like some custom code you have setup which is passing through the wrong group id. Its indicated by the API identifier in the failure. I would check what custom code you have and establish where group 13 is being passed in, you could turn on the backtrace recording so that the exact source can be determined.
  
  The other thing to check is that the contribution page is set correctly in the section where contacts are automatically added to groups. Someone may have set it there and subsequently removed the group.
  
  Either may cause this issue.
  
  > **Comments:**
  > **username_0**: I have found that group 13 exists but was not enabled. It is now deleted.  
  > **username_0**: By turn on the backtrace do you mean turn on debugging?  
  > **username_2**: @username_0 - If you go to **Administer menu » System Settings » Debugging and Error Handling**, you'll see there is a separate option for enabling backtraces in addition to enabling debugging.  Turning on both is essential for troubleshooting issues like this.  If you update your question with a backtrace in addition to what you provided, it's likely someone could better point out the nature of your problem.  
  
  ---
  
  