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 »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Cannot add or update a child row: a foreign key constraint fails
Pages: [1]

Author Topic: Cannot add or update a child row: a foreign key constraint fails  (Read 9187 times)

ryanpitt

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 0
Cannot add or update a child row: a foreign key constraint fails
November 03, 2008, 12:41:24 pm
Hi All,
I received the following error while trying to run an advanced search after upgrading CiviCRM 2.03 to 2.1.1
The search criteria was a certain group and a range of Zip codes within that group.
Any ideas?
Using Drupal 6.6 and CiviCRM 2.1.1
Thanks
Ryan


Advanced Search
 Sorry. A non-recoverable error has occurred.
--------------------------------------------------------------------------------
DB Error: constraint violation

Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`civicrmtest/civicrm_group_contact_cache`, CONSTRAINT `FK_civicrm_group_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE), 1452

Return to home page.

Error Details:

Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (12,15434),(12,16070),(12,10643),(12,15941),(12,15942); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrmtest/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] => REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (12,15434),(12,16070),(12,10643),(12,15941),(12,15942); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrmtest/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="REPLACE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES (12,15434),(12,16070),(12,10643),(12,15941),(12,15942); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrmtest/civicrm_group_contact_cache`, CONSTRAINT `FK_civicrm_group_contact_cache_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE)]"]
)


Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: Cannot add or update a child row: a foreign key constraint fails
November 04, 2008, 08:55:14 pm
I am not sure what could be the reason, but since 'civicrm_group_contact_cache' table is mainly used for caching purpose, its safe/ok to empty it and check if that solves your problem.

Code: [Select]
truncate civicrm_group_contact_cache;
update civicrm_group set cache_date = null;
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

mac

  • I post occasionally
  • **
  • Posts: 71
  • Karma: 0
Re: Cannot add or update a child row: a foreign key constraint fails
February 11, 2010, 07:03:25 am
I just had a similar problem. I did run both queries as indicated in the previous post, but it didn't help.

I had to go in through MySQL Admin/Browser and delete the smart group I recently created. Additionally I also saw that another group must have been created automatically (does CiviCRM create two group entries / smart group?), so I deleted it as well.

Everything seems to be working fine now.

What might be going on? Smart groups are a nice feature, but if they such trouble, I'm afraid to use them.

Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: Cannot add or update a child row: a foreign key constraint fails
February 11, 2010, 10:49:02 am
There has been lots of fixes / improvements w.r.t handling of caches. You might want to upgrade to the latest version.
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

mac

  • I post occasionally
  • **
  • Posts: 71
  • Karma: 0
Re: Cannot add or update a child row: a foreign key constraint fails
February 11, 2010, 10:52:36 am
Oops ... we actually have recently upgraded to 3.0.3 recently. I just forgot to update my forum profile.

Would you recommend to upgrade to 3.1?

Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: Cannot add or update a child row: a foreign key constraint fails
February 11, 2010, 11:02:24 am
Code: [Select]
Would you recommend to upgrade to 3.1?yes, most recommended.
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Sam Rose

  • Guest
Re: Cannot add or update a child row: a foreign key constraint fails
April 01, 2010, 07:46:12 am
Wanted to report that clearing civicrm cache table solved this problem for me. (using civicrm 3.1.2 Drual 6 mysql 5 and php 5.2.0 as of this writing)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Cannot add or update a child row: a foreign key constraint fails

This forum was archived on 2017-11-26.