Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Major
-
Resolution: Duplicate
-
Affects Version/s: 2.0
-
Fix Version/s: None
-
Component/s: Core CiviCRM
-
Labels:None
Description
Steps to reproduce:
1. An individual is created via the API
2. A note is created and associated with that individual again via the API
3. View the user in the GUI
4. Delete the user from the GUI
The following error message is displayed: (see end of description).
This does not happen if the user is created via the GUI and then a note is added to the user again via the GUI and then the user is deleted again via the GUI.
ERROR MESSAGE
===========
Array
(
[callback] => Array
(
[0] => CRM_Core_Error
[1] => handle
)
[code] => -1
[message] => DB Error: unknown error
[mode] => 16
[debug_info] => DELETE FROM civicrm_contact WHERE ( civicrm_contact.id = 33 ) [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`civicrm/civicrm_note`, CONSTRAINT `FK_civicrm_note_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
[type] => DB_Error
[user_info] => DELETE FROM civicrm_contact WHERE ( civicrm_contact.id = 33 ) [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`civicrm/civicrm_note`, CONSTRAINT `FK_civicrm_note_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
[to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="DELETE FROM civicrm_contact WHERE ( civicrm_contact.id = 33 ) [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`civicrm/civicrm_note`, CONSTRAINT `FK_civicrm_note_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]"]
)
CODE SNIPPET USED TO CREATE USER
=========================
$params = array(
"contact_type" => "Individual",
"first_name" => $contact[$contactnum]["first"],
"middle_name" => $contact[$contactnum]["middle"],
"last_name" => $contact[$contactnum]["last"],
"job_title" => $contact[$contactnum]["title"],
"email" => $contact[$contactnum]["email"],
"home_URL" => $contact[$contactnum]["url"]
);
$addedContact = &civicrm_contact_add($params);
CODE SNIPPET USED TO ADD NOTE TO USER
=============================
$params = array(
'entity_table' => "civicrm_contact",
'entity_id' => $addedContact['contact_id'],
'note' => $contact[$contactnum]["memo"],
'contact_id' => $addedContact['contact_id'],
'modified_date' => date("Ymd"),
'subject' => "Note imported from RMMS CHQ Database"
);
$noteCreated = &civicrm_note_create($params);