Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Major
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.3.0
-
Fix Version/s: 4.3.0
-
Component/s: None
-
Labels:None
Description
We need to check the DB for contribution rows with FK to non-existent contact record before proceeding w/ upgrade (upgrade throws fatal below if those exist).
Run this query:
select COUNT(ct.id) from civicrm_contribution ct left join civicrm_contact c ON ct.contact_id = c.id where c.id IS NULL ;
If count > 0, abort the upgrade with message:
"There is a data integrity issue with this CiviCRM database. It contains $count contribution records which are linked to contact records that have been deleted. You will need to correct this manually before you can run the upgrade. Use the following MySQL query to identify the problem records: <em>SELECT CT.* FROM civicrm_contribution CT LEFT JOIN civicrm_contact c ON ct.contact_id = c.id WHERE c.id IS NULL;</em> These records will need to be deleted or linked to an existing contact record."
Deepak - please also fix this typo in FourThree.php while you're in there:
CURRENT:
$postUpgradeMessage .= '<br />' . ts("The existing organization contact record for '{$orgName}' has marked as the default domain contact, and has been updated with information from your Organization Address and Contact Info settings.");
SHOULD BE (add 'been'):
$postUpgradeMessage .= '<br />' . ts("The existing organization contact record for '{$orgName}' has been marked as the default domain contact, and has been updated with information from your Organization Address and Contact Info settings.");
---original post —
Hopefully this backtrace helps / means something. This was an upgrade from 4.2.2, reasonably customised… Let me know if you need anymore info…
Mar 11 16:12:15 [info] $backTrace = #0 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/Error.php(751): CRM_Core_Error::backtrace("backTrace", TRUE)
#1 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error))
#2 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
#3 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB.php(969): PEAR_Error->PEAR_Error("DB Error: constraint violation", -3, 16, (Array:2), "\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#4 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error->DB_Error(-3, 16, (Array:2), "\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#5 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -3, NULL, NULL, "\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...", "DB_Error", TRUE)
#6 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/mysql.php(898): DB_common->raiseError(-3, NULL, NULL, NULL, "1452 ** Cannot add or update a child row: a foreign key constraint fails (`gr...")
#7 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/mysql.php(327): DB_mysql->mysqlRaiseError()
#8 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql->simpleQuery("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#9 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/DataObject.php(2421): DB_common->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#10 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/DataObject.php(1613): DB_DataObject->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact...")
#11 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/DAO.php(155): DB_DataObject->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#12 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/DAO.php(917): CRM_Core_DAO->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...", TRUE)
#13 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Upgrade/Incremental/php/FourThree.php(444): CRM_Core_DAO::executeQuery("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...", (Array:3))
#14 [internal function](): CRM_Upgrade_Incremental_php_FourThree::createFinancialRecords(Object(CRM_Queue_TaskContext))
#15 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Task.php(79): call_user_func_array((Array:2), (Array:1))
#16 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Runner.php(186): CRM_Queue_Task->run(Object(CRM_Queue_TaskContext))
#17 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Page/AJAX.php(44): CRM_Queue_Runner->runNext(TRUE)
#18 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/ErrorPolicy.php(80):
#19 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Page/AJAX.php(47): CRM_Queue_ErrorPolicy->call(Object(Closure))
#20 [internal function](): CRM_Queue_Page_AJAX::runNext((Array:5))
#21 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/Invoke.php(258): call_user_func((Array:2), (Array:5))
#22 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/Invoke.php(70): CRM_Core_Invoke::runItem((Array:4))
#23 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:5))
#24 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/drupal/civicrm.module(407): CRM_Core_Invoke::invoke((Array:5))
#25 [internal function](): civicrm_invoke("upgrade", "queue", "ajax", "runNext")
#26 /Library/WebServer/Documents/greenrenters_7_civ43/includes/menu.inc(517): call_user_func_array("civicrm_invoke", (Array:4))
#27 /Library/WebServer/Documents/greenrenters_7_civ43/index.php(25): menu_execute_active_handler()
#28 {main}
Mar 11 16:12:15 [info] $CRM_Queue_Page_AJAX_runNext_error = PEAR_Exception: "DB Error: constraint violation"
* ERROR TYPE: DB_Error
* ERROR CODE: -3
* ERROR MESSAGE: DB Error: constraint violation
* ERROR MODE: 16
* ERROR USERINFO:
INSERT INTO civicrm_financial_item
(transaction_date, contact_id, amount, currency, entity_table, entity_id, description, status_id, financial_account_id, f_trxn_id)
SELECT REPLACE(REPLACE(REPLACE(ft.trxn_date, '-', ''), ':', ''), ' ', ''), con.contact_id,
IF(ft.total_amount < 0 AND con.contribution_status_id = 3, -li.line_total, li.line_total) as line_total,
con.currency, 'civicrm_line_item', li.id as line_item_id, li.label as line_item_label,
IF(con.contribution_status_id = 2, 3, 1) as status_id,
efa.financial_account_id as financial_account_id, ft.id as f_trxn_id
FROM civicrm_line_item li
INNER JOIN civicrm_participant par
ON (li.entity_id = par.id AND li.entity_table = 'civicrm_participant')
INNER JOIN civicrm_participant_payment pp
ON (pp.participant_id = par.id)
INNER JOIN civicrm_contribution con
ON (pp.contribution_id = con.id)
INNER JOIN civicrm_financial_trxn ft
ON (con.id = ft.contribution_id)
LEFT JOIN civicrm_entity_financial_account efa
ON (li.financial_type_id = efa.entity_id AND
efa.entity_table = 'civicrm_financial_type' AND efa.account_relationship = 1)
WHERE con.contribution_status_id IN (1, 3) OR (con.is_pay_later = 1 AND con.contribution_status_id = 2) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gr7_civ43_localdb`.`civicrm_financial_item`, CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
* ERROR DEBUGINFO:
INSERT INTO civicrm_financial_item
(transaction_date, contact_id, amount, currency, entity_table, entity_id, description, status_id, financial_account_id, f_trxn_id)
SELECT REPLACE(REPLACE(REPLACE(ft.trxn_date, '-', ''), ':', ''), ' ', ''), con.contact_id,
IF(ft.total_amount < 0 AND con.contribution_status_id = 3, -li.line_total, li.line_total) as line_total,
con.currency, 'civicrm_line_item', li.id as line_item_id, li.label as line_item_label,
IF(con.contribution_status_id = 2, 3, 1) as status_id,
efa.financial_account_id as financial_account_id, ft.id as f_trxn_id
FROM civicrm_line_item li
INNER JOIN civicrm_participant par
ON (li.entity_id = par.id AND li.entity_table = 'civicrm_participant')
INNER JOIN civicrm_participant_payment pp
ON (pp.participant_id = par.id)
INNER JOIN civicrm_contribution con
ON (pp.contribution_id = con.id)
INNER JOIN civicrm_financial_trxn ft
ON (con.id = ft.contribution_id)
LEFT JOIN civicrm_entity_financial_account efa
ON (li.financial_type_id = efa.entity_id AND
efa.entity_table = 'civicrm_financial_type' AND efa.account_relationship = 1)
WHERE con.contribution_status_id IN (1, 3) OR (con.is_pay_later = 1 AND con.contribution_status_id = 2) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`gr7_civ43_localdb`.`civicrm_financial_item`, CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
#0 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error))
#1 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
#2 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB.php(969): PEAR_Error->PEAR_Error("DB Error: constraint violation", -3, 16, (Array:2), "\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#3 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error->DB_Error(-3, 16, (Array:2), "\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#4 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -3, NULL, NULL, "\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...", "DB_Error", TRUE)
#5 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/mysql.php(898): DB_common->raiseError(-3, NULL, NULL, NULL, "1452 ** Cannot add or update a child row: a foreign key constraint fails (`gr...")
#6 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/mysql.php(327): DB_mysql->mysqlRaiseError()
#7 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql->simpleQuery("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#8 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/DataObject.php(2421): DB_common->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#9 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/packages/DB/DataObject.php(1613): DB_DataObject->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact...")
#10 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/DAO.php(155): DB_DataObject->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...")
#11 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/DAO.php(917): CRM_Core_DAO->query("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...", TRUE)
#12 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Upgrade/Incremental/php/FourThree.php(444): CRM_Core_DAO::executeQuery("\nINSERT INTO civicrm_financial_item \n (transaction_date, contact_...", (Array:3))
#13 [internal function](): CRM_Upgrade_Incremental_php_FourThree::createFinancialRecords(Object(CRM_Queue_TaskContext))
#14 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Task.php(79): call_user_func_array((Array:2), (Array:1))
#15 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Runner.php(186): CRM_Queue_Task->run(Object(CRM_Queue_TaskContext))
#16 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Page/AJAX.php(44): CRM_Queue_Runner->runNext(TRUE)
#17 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/ErrorPolicy.php(80): {closure}
()
#18 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Queue/Page/AJAX.php(47): CRM_Queue_ErrorPolicy->call(Object(Closure))
#19 [internal function](): CRM_Queue_Page_AJAX::runNext((Array:5))
#20 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/Invoke.php(258): call_user_func((Array:2), (Array:5))
#21 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/Invoke.php(70): CRM_Core_Invoke::runItem((Array:4))
#22 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:5))
#23 /Library/WebServer/Documents/greenrenters_7_civ43/sites/all/modules/civicrm/drupal/civicrm.module(407): CRM_Core_Invoke::invoke((Array:5))
#24 [internal function](): civicrm_invoke("upgrade", "queue", "ajax", "runNext")
#25 /Library/WebServer/Documents/greenrenters_7_civ43/includes/menu.inc(517): call_user_func_array("civicrm_invoke", (Array:4))
#26 /Library/WebServer/Documents/greenrenters_7_civ43/index.php(25): menu_execute_active_handler()
#27