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) »
  • DB error: Cannot add or update a child row: a foreign key constraint fails
Pages: [1]

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

shakergeek

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.08
  • CMS version: Drupal 7
  • MySQL version: 5.1.49
  • PHP version: 5.3.13
DB error: Cannot add or update a child row: a foreign key constraint fails
June 05, 2013, 09:13:24 am
hello,

Getting an error when we try to add a new meeting from the contact search results page, anyone have an idea what going on here:

Code: [Select]
[debug_info] => INSERT INTO civicrm_activity_target ( activity_id, target_contact_id ) VALUES ( 2049, 5079 ); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`onehealth_civi`.`civicrm_activity_target`, CONSTRAINT `FK_civicrm_activity_target_activity_id` FOREIGN KEY (`activity_id`) REFERENCES `___temp_dreamhost_restore_20130525_081805`.`civicrm_acti)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_activity_target ( activity_id, target_contact_id ) VALUES ( 2049, 5079 ); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`onehealth_civi`.`civicrm_activity_target`, CONSTRAINT `FK_civicrm_activity_target_activity_id` FOREIGN KEY (`activity_id`) REFERENCES `___temp_dreamhost_restore_20130525_081805`.`civicrm_acti)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_activity_target ( activity_id, target_contact_id ) VALUES ( 2049, 5079 ); [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`onehealth_civi`.`civicrm_activity_target`, CONSTRAINT `FK_civicrm_activity_target_activity_id` FOREIGN KEY (`activity_id`) REFERENCES `___temp_dreamhost_restore_20130525_081805`.`civicrm_acti)]"]

thanks

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: DB error: Cannot add or update a child row: a foreign key constraint fails
June 05, 2013, 09:22:50 am
Hi there,

The last line says:
CONSTRAINT `FK_civicrm_activity_target_activity_id` FOREIGN KEY (`activity_id`) REFERENCES `___temp_dreamhost_restore_20130525_081805`.`civicrm_acti)]"

The part that concerns me is this:
___temp_dreamhost_restore_20130525_081805

If I had to gues, I'd say that your web host is Dreamhost, and at some point you had to restore your CiviCRM database from a backup, but it was improperly restored.

I'm not sure I can recommend the best course of action for fixing this, since there are probably bad foreign keys everywhere.  You may have to go in and edit them manually - but that's not a trivial task.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • DB error: Cannot add or update a child row: a foreign key constraint fails

This forum was archived on 2017-11-26.