1

I get the following errors while importing a contact CSV file. I hope somebody can help with the issue. Civicrm 5 latest with WP 5 latest and the error is same with both PHP 5 and 7.2.

"Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing when this occurred.
DB Error: constraint violation
Error Details
Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`wp_23ye3`.`civicrm_address`, CONSTRAINT `FK_civicrm_address_master_id` FOREIGN KEY (`master_id`) REFERENCES `civicrm_address` (`id`) ON DELETE SET NULL), 1452
Additional Details:
Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_address (contact_id , location_type_id , is_primary , is_billing , street_address , supplemental_address_1 , city , state_province_id , postal_code , country_id , manual_geo_code , master_id ) VALUES ( 10 ,  1 ,  1 ,  0 , 'Lakhimi Nagar Hatigaon' , 'Dispur' , 'Guwahati' ,  1204 , '781006' ,  1101 ,  0 ,  0 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`wp_23ye3`.`civicrm_address`, CONSTRAINT `FK_civicrm_address_master_id` FOREIGN KEY (`master_id`) REFERENCES `civicrm_address` (`id`) ON DELETE SET NULL)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_address (contact_id , location_type_id , is_primary , is_billing , street_address , supplemental_address_1 , city , state_province_id , postal_code , country_id , manual_geo_code , master_id ) VALUES ( 10 ,  1 ,  1 ,  0 , 'Lakhimi Nagar Hatigaon' , 'Dispur' , 'Guwahati' ,  1204 , '781006' ,  1101 ,  0 ,  0 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`wp_23ye3`.`civicrm_address`, CONSTRAINT `FK_civicrm_address_master_id` FOREIGN KEY (`master_id`) REFERENCES `civicrm_address` (`id`) ON DELETE SET NULL)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_address (contact_id , location_type_id , is_primary , is_billing , street_address , supplemental_address_1 , city , state_province_id , postal_code , country_id , manual_geo_code , master_id ) VALUES ( 10 ,  1 ,  1 ,  0 , 'Lakhimi Nagar Hatigaon' , 'Dispur' , 'Guwahati' ,  1204 , '781006' ,  1101 ,  0 ,  0 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`wp_23ye3`.`civicrm_address`, CONSTRAINT `FK_civicrm_address_master_id` FOREIGN KEY (`master_id`) REFERENCES `civicrm_address` (`id`) ON DELETE SET NULL)]"]
)"

Additional Error after enabling debugging

2
  • Hmm you are capturing everything except the actual error & actual query - is this from the log or the UI?
    – eileen
    May 31, 2019 at 22:19
  • Hi, this is from the UI. The actual error is: "Sorry, due to an error, we are unable to fulfill your request at the moment. You may want to contact your administrator or service provider with more details about what action you were performing when this occurred." Then in the detail of the error, I get " Database Error Code: Cannot add or update a child row: a foreign key constraint fails (wp_23ye3.civicrm_address, CONSTRAINT FK_civicrm_address_master_id FOREIGN KEY (master_id) REFERENCES civicrm_address (id) ON DELETE SET NULL), 1452" The some additional details... Jun 1, 2019 at 13:26

1 Answer 1

2

It sounds like you have selected one of the columns to be "Master Address Belongs To". If the record that column references doesn't exist yet you will get this error. Also FYI it looks like that column needs to be an integer.

1
  • hence if you have some with a value and some without, try doing as 2 separate imports
    – petednz - fuzion
    Jun 5, 2019 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.