Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-12498

API contribution.create/update DB Error: constraint violation

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.3.1
    • Fix Version/s: 4.3.4
    • Component/s: CiviCRM API
    • Labels:
      None

      Description

      Hi,

      Cannot add or update a child row: a foreign key constraint fails (`civi_demo`.`civicrm_financial_item`, CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]

      Seen with Joe, it seems it shouldn't touch the civicrm_financial_item on update at all, so might have lost somewhere the info it's an update, not a creation?

      Step to reproduce: create a normal contribution (from a contrib page).

      Modify the status using the api:

      $params = array(
      'version' => 3,
      'id' => 42,
      'contribution_status_id' => 2,
      'sequential' => 1,
      );
      $result = civicrm_api('Contribution', 'create', $params);

      Was expecting to have the status changed, but got a constraint violation on the financial item. On a different/previous test, I had a different message about an activity (but I couldn't reproduce). Might have been on a contrib created from the back office.

      Result as created by the api explorer (with debug on)

      {
      "error_code":"constraint violation",
      "sql":"INSERT INTO civicrm_financial_item (transaction_date , description , amount , currency , financial_account_id , status_id , entity_table , entity_id ) VALUES ( 0 , ' gev' , 125.00 , 'CHF' , 3 , 3 , 'civicrm_line_item' , 1 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civi_demo`.`civicrm_financial_item`, CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]",
      "debug_info":"INSERT INTO civicrm_financial_item (transaction_date , description , amount , currency , financial_account_id , status_id , entity_table , entity_id ) VALUES ( 0 , ' gev' , 125.00 , 'CHF' , 3 , 3 , 'civicrm_line_item' , 1 ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civi_demo`.`civicrm_financial_item`, CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]",
      "trace":"#0 [internal function]: CRM_Core_Error::exceptionHandler(Object(DB_Error))\n#1 \/var\/projects\/civi.43\/packages\/PEAR.php(931): call_user_func(Array, Object(DB_Error))\n#2 \/var\/projects\/civi.43\/packages\/DB.php(969): PEAR_Error->PEAR_Error('DB Error: const...', 3, 16, Array, 'INSERT INTO civ...')\n#3 \/var\/projects\/civi.43\/packages\/PEAR.php(564): DB_Error>DB_Error(3, 16, Array, 'INSERT INTO civ...')\n#4 \/var\/projects\/civi.43\/packages\/DB\/common.php(1905): PEAR>raiseError(NULL, 3, NULL, NULL, 'INSERT INTO civ...', 'DB_Error', true)\n#5 \/var\/projects\/civi.43\/packages\/DB\/mysql.php(898): DB_common>raiseError(3, NULL, NULL, NULL, '1452 ** Cannot ...')\n#6 \/var\/projects\/civi.43\/packages\/DB\/mysql.php(327): DB_mysql>mysqlRaiseError()\n#7 \/var\/projects\/civi.43\/packages\/DB\/common.php(1216): DB_mysql->simpleQuery('INSERT INTO civ...')\n#8 \/var\/projects\/civi.43\/packages\/DB\/DataObject.php(2421): DB_common->query('INSERT INTO civ...')\n#9 \/var\/projects\/civi.43\/packages\/DB\/DataObject.php(1055): DB_DataObject->_query('INSERT INTO civ...')\n#10 \/var\/projects\/civi.43\/CRM\/Core\/DAO.php(287): DB_DataObject->insert()\n#11 \/var\/projects\/civi.43\/CRM\/Financial\/BAO\/FinancialItem.php(136): CRM_Core_DAO->save()\n#12 \/var\/projects\/civi.43\/CRM\/Financial\/BAO\/FinancialItem.php(115): CRM_Financial_BAO_FinancialItem::create(Array, NULL, Array)\n#13 \/var\/projects\/civi.43\/CRM\/Price\/BAO\/LineItem.php(294): CRM_Financial_BAO_FinancialItem::add(Object(CRM_Price_BAO_LineItem), Object(CRM_Contribute_BAO_Contribution))\n#14 \/var\/projects\/civi.43\/CRM\/Contribute\/BAO\/Contribution.php(2784): CRM_Price_BAO_LineItem::processPriceSet('1', Array, Object(CRM_Contribute_BAO_Contribution), 'civicrm_contrib...', false)\n#15 \/var\/projects\/civi.43\/CRM\/Contribute\/BAO\/Contribution.php(178): CRM_Contribute_BAO_Contribution::recordFinancialAccounts(Array, Array)\n#16 \/var\/projects\/civi.43\/CRM\/Contribute\/BAO\/Contribution.php(266): CRM_Contribute_BAO_Contribution::add(Array, Array)\n#17 \/var\/projects\/civi.43\/api\/v3\/Contribution.php(66): CRM_Contribute_BAO_Contribution::create(Array, Array)\n#18 \/var\/projects\/civi.43\/api\/api.php(75): civicrm_api3_contribution_create(Array)\n#19 \/var\/projects\/civi.43\/CRM\/Utils\/REST.php(412): civicrm_api('Contribution', 'create', Array)\n#20 \/var\/projects\/civi.43\/CRM\/Utils\/REST.php(634): CRM_Utils_REST::process(Array, false)\n#21 [internal function]: CRM_Utils_REST::ajax(Array)\n#22 \/var\/projects\/civi.43\/CRM\/Core\/Invoke.php(258): call_user_func(Array, Array)\n#23 \/var\/projects\/civi.43\/CRM\/Core\/Invoke.php(70): CRM_Core_Invoke::runItem(Array)\n#24 \/var\/projects\/civi.43\/CRM\/Core\/Invoke.php(52): CRM_Core_Invoke::_invoke(Array)\n#25 \/var\/projects\/civi.43\/drupal\/civicrm.module(436): CRM_Core_Invoke::invoke(Array)\n#26 [internal function]: civicrm_invoke('ajax', 'rest')\n#27 \/var\/projects\/drupal\/43\/includes\/menu.inc(517): call_user_func_array('civicrm_invoke', Array)\n#28 \/var\/projects\/drupal\/43\/index.php(21): menu_execute_active_handler()\n#29

      {main}

      ",
      "is_error":1,
      "error_message":"DB Error: constraint violation"
      }

        Attachments

          Activity

            People

            • Assignee:
              xavier xavier dutoit
              Reporter:
              xavier xavier dutoit
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: