CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Foreign Key error when searching/listing contacts
Pages: [1]

Author Topic: Foreign Key error when searching/listing contacts  (Read 515 times)

Upperholme

  • Administrator
  • Ask me questions
  • *****
  • Posts: 568
  • Karma: 8
    • MC3
  • CiviCRM version: 4.x
  • CMS version: Drupal 6.x/7.x, Wordpress, Joomla
Foreign Key error when searching/listing contacts
September 28, 2012, 03:37:30 am
This is a Wordpress site running CiviCRM 4.1.3. It's been working fine for the last few weeks, and today has started throwing fatal errors when searching for contacts and listing contacts from the Groups listing. The detail:

Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`carplusorg_civicrm`.`civicrm_group_contact_cache`, CONSTRAINT `FK_civicrm_group_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE), 1452
Additional Details:
Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (2,10),(2,101),(2,103),(2,105),(2,107),(2,108),(2,109),(2,11),(2,111),(2,112),(2,113),(2,114),(2,115),(2,116),(2,117),(2,119),(2,12),(2,121),(2,122),(2,123),(2,124),(2,125),(2,126),(2,128),(2,129),(2,13),(2,130),(2,131),(2,132),(2,133),(2,134),(2,135),(2,136),(2,137),(2,138),(2,139),(2,140),(2,141),(2,142),(2,144),(2,145),(2,146),(2,147),(2,148),(2,149),(2,15),(2,151),(2,153),(2,155),(2,157),(2,159),(2,16),(2,160),(2,161),(2,162),(2,17),(2,178),(2,18),(2,20),(2,21),(2,218),(2,219),(2,22),(2,25),(2,26),(2,27),(2,28),(2,284),(2,285),(2,29),(2,291),(2,30),(2,31),(2,32),(2,33),(2,34),(2,35),(2,36),(2,37),(2,38),(2,39),(2,40),(2,41),(2,42),(2,43),(2,45),(2,46),(2,47),(2,49),(2,50),(2,51),(2,518),(2,52),(2,53),(2,54),(2,541),(2,55),(2,56),(2,57),(2,58),(2,59),(2,60),(2,61),(2,610),(2,611),(2,62),(2,63),(2,65),(2,67),(2,69),(2,7),(2,70),(2,71),(2,73),(2,74),(2,75),(2,76),(2,77),(2,78),(2,8),(2,81),(2,82),(2,83),(2,85),(2,86),(2,87),(2,88),(2,89),(2,9),(2,91),(2,93),(2,95),(2,9502),(2,9533),(2,9534),(2,9577),(2,9578),(2,9602),(2,97),(2,9751),(2,9758),(2,9774),(2,9781),(2,99),(2,9925),(2,9967),(2,9974),(2,9976),(2,9977); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`carplusorg_civicrm`.`civicrm_group_contact_cache`, CONSTRAINT `FK_civicrm_group_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (2,10),(2,101),(2,103),(2,105),(2,107),(2,108),(2,109),(2,11),(2,111),(2,112),(2,113),(2,114),(2,115),(2,116),(2,117),(2,119),(2,12),(2,121),(2,122),(2,123),(2,124),(2,125),(2,126),(2,128),(2,129),(2,13),(2,130),(2,131),(2,132),(2,133),(2,134),(2,135),(2,136),(2,137),(2,138),(2,139),(2,140),(2,141),(2,142),(2,144),(2,145),(2,146),(2,147),(2,148),(2,149),(2,15),(2,151),(2,153),(2,155),(2,157),(2,159),(2,16),(2,160),(2,161),(2,162),(2,17),(2,178),(2,18),(2,20),(2,21),(2,218),(2,219),(2,22),(2,25),(2,26),(2,27),(2,28),(2,284),(2,285),(2,29),(2,291),(2,30),(2,31),(2,32),(2,33),(2,34),(2,35),(2,36),(2,37),(2,38),(2,39),(2,40),(2,41),(2,42),(2,43),(2,45),(2,46),(2,47),(2,49),(2,50),(2,51),(2,518),(2,52),(2,53),(2,54),(2,541),(2,55),(2,56),(2,57),(2,58),(2,59),(2,60),(2,61),(2,610),(2,611),(2,62),(2,63),(2,65),(2,67),(2,69),(2,7),(2,70),(2,71),(2,73),(2,74),(2,75),(2,76),(2,77),(2,78),(2,8),(2,81),(2,82),(2,83),(2,85),(2,86),(2,87),(2,88),(2,89),(2,9),(2,91),(2,93),(2,95),(2,9502),(2,9533),(2,9534),(2,9577),(2,9578),(2,9602),(2,97),(2,9751),(2,9758),(2,9774),(2,9781),(2,99),(2,9925),(2,9967),(2,9974),(2,9976),(2,9977); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`carplusorg_civicrm`.`civicrm_group_contact_cache`, CONSTRAINT `FK_civicrm_group_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (2,10),(2,101),(2,103),(2,105),(2,107),(2,108),(2,109),(2,11),(2,111),(2,112),(2,113),(2,114),(2,115),(2,116),(2,117),(2,119),(2,12),(2,121),(2,122),(2,123),(2,124),(2,125),(2,126),(2,128),(2,129),(2,13),(2,130),(2,131),(2,132),(2,133),(2,134),(2,135),(2,136),(2,137),(2,138),(2,139),(2,140),(2,141),(2,142),(2,144),(2,145),(2,146),(2,147),(2,148),(2,149),(2,15),(2,151),(2,153),(2,155),(2,157),(2,159),(2,16),(2,160),(2,161),(2,162),(2,17),(2,178),(2,18),(2,20),(2,21),(2,218),(2,219),(2,22),(2,25),(2,26),(2,27),(2,28),(2,284),(2,285),(2,29),(2,291),(2,30),(2,31),(2,32),(2,33),(2,34),(2,35),(2,36),(2,37),(2,38),(2,39),(2,40),(2,41),(2,42),(2,43),(2,45),(2,46),(2,47),(2,49),(2,50),(2,51),(2,518),(2,52),(2,53),(2,54),(2,541),(2,55),(2,56),(2,57),(2,58),(2,59),(2,60),(2,61),(2,610),(2,611),(2,62),(2,63),(2,65),(2,67),(2,69),(2,7),(2,70),(2,71),(2,73),(2,74),(2,75),(2,76),(2,77),(2,78),(2,8),(2,81),(2,82),(2,83),(2,85),(2,86),(2,87),(2,88),(2,89),(2,9),(2,91),(2,93),(2,95),(2,9502),(2,9533),(2,9534),(2,9577),(2,9578),(2,9602),(2,97),(2,9751),(2,9758),(2,9774),(2,9781),(2,99),(2,9925),(2,9967),(2,9974),(2,9976),(2,9977); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`carplusorg_civicrm`.`civicrm_group_contact_cache`, CONSTRAINT `FK_civicrm_group_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]"]
)

I've no idea currently what may have triggered this problem, but I'm keen to get it resolved ASAP as this is production site.
Any input most welcome.

Thanks
Graham
Graham Mitchell
http://mc3.coop

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Foreign Key error when searching/listing contacts
September 29, 2012, 06:09:03 pm
Seems that it's trying to insert a record into a cache table which refers to a non-existent Contact. Did you delete any contacts recently?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Upperholme

  • Administrator
  • Ask me questions
  • *****
  • Posts: 568
  • Karma: 8
    • MC3
  • CiviCRM version: 4.x
  • CMS version: Drupal 6.x/7.x, Wordpress, Joomla
Re: Foreign Key error when searching/listing contacts
September 30, 2012, 12:14:14 am
Hi Hershel, thanks.

I reached the same conclusion after a lot of reading and poring over the details of the error report. There was one contact record that was referred to in the query that had been deleted.

What I don't understand is why the deleted contact is being referred to in the query? Presumably the contact deletion was in some way incomplete? What is the best approach to take to deal with it?
Graham Mitchell
http://mc3.coop

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Foreign Key error when searching/listing contacts
October 08, 2012, 01:00:00 pm
I don't know why it refers to the deleted contact. To fix it, perhaps try deleting template files and flushing all caches...
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Foreign Key error when searching/listing contacts

This forum was archived on 2017-11-26.