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 »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Foreign key constraint error - cannot seem to resolve this
Pages: [1]

Author Topic: Foreign key constraint error - cannot seem to resolve this  (Read 6175 times)

jmsobe

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
Foreign key constraint error - cannot seem to resolve this
April 29, 2007, 06:19:44 am
Been going crazy trying to debug this. I moving from a local installation where the site was developed to my production environment. I am using the latest 1.7 beta of Civicrm.

Getting this error:

Sorry. A non-recoverable error has occurred.
Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`jmayer_bvcivicrm/civicrm_contact`, CONSTRAINT `FK_civicrm_contact_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain` (`id`)), 1452

Return to CiviCRM menu.

Code: [Select]
Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_contact (domain_id , contact_type , sort_name , display_name , hash ) VALUES ( 0 , 'Individual' , 'joe.smith@gmail.com' , 'joe.smith@gmail.com' , '0b3d427191fc5daafafed6d9213311de' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`jmayer_bvcivicrm/civicrm_contact`, CONSTRAINT `FK_civicrm_contact_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain` (`id`))]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_contact (domain_id , contact_type , sort_name , display_name , hash ) VALUES ( 0 , 'Individual' , 'joe.smith@gmail.com' , 'joe.smith@gmail.com' , '0b3d427191fc5daafafed6d9213311de' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`jmayer_bvcivicrm/civicrm_contact`, CONSTRAINT `FK_civicrm_contact_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain` (`id`))]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_contact (domain_id , contact_type , sort_name , display_name , hash ) VALUES ( 0 , 'Individual' , 'joe.smith@gmail.com' , 'joe.smith@gmail.com' , '0b3d427191fc5daafafed6d9213311de' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`jmayer_bvcivicrm/civicrm_contact`, CONSTRAINT `FK_civicrm_contact_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain` (`id`))]"]
)


Using PHP 5 and MYSQL 5
[/code]

stephenrockwell

  • Guest
Re: Foreign key constraint error - cannot seem to resolve this
April 29, 2007, 08:29:03 am
I'm getting the same exact error with my install using 1.7

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Foreign key constraint error - cannot seem to resolve this
April 29, 2007, 11:35:59 am

Stephen / JMSobe:

  • Did u load civicrm_data.mysql OR civicrm_generated.mysql into your mysql database
  • Do you have the below DEFINE in your civicrm.settings.php file

    define('CIVICRM_DOMAIN_ID' , 1 );

    I suspect this is the cause, since your domain_id value is 0 in the mysql statements

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jmsobe

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
Re: Foreign key constraint error - cannot seem to resolve this
May 15, 2007, 05:20:49 pm
Donald,


I have am using civicrm_data.mysql. I don't have any real data yet in CiviCrm so I will reload the data if necessary using the generated file if that will fix my problem. My domain id is

define('CIVICRM_DOMAIN_ID' , 0 );

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Foreign key constraint error - cannot seem to resolve this
May 15, 2007, 05:47:51 pm
Try changing your civicrm.settings.php domain ID to 1 (which is the default for a single domain install). I don't think 0 works. Not sure how you got 0 as your value ???

define('CIVICRM_DOMAIN_ID' , 1 );

You might want to drop the DB and reload civicrm_41.mysql and civicrm_data.mysql after making this change and before accessing the site - as the 0 setting might have left some undesired entries in the DB.
Protect your investment in CiviCRM by  becoming a Member!

joeshirley

  • Guest
Re: Foreign key constraint error - cannot seem to resolve this
May 21, 2007, 04:27:48 pm
Quote from: Donald Lobo on April 29, 2007, 11:35:59 am

  • Did u load civicrm_data.mysql OR civicrm_generated.mysql into your mysql database
  • Do you have the below DEFINE in your civicrm.settings.php file

    define('CIVICRM_DOMAIN_ID' , 1 );


lobo


I too was getting this foreign key constraint error. However, my civicrm.settings.php has define('CIVICRM_DOMAIN_ID' , 1 ); I used civicrm_generated.mysql, (and got a similar foreign key error when running the script, which I ignored unfortunately).

Anyway, based on your advice, I dropped my tables, reimported civicrm_41.mysql followed by civicrm_data.mysql, and everything is now running fine.

I'm thinking there's a problem with the 'generated' version of the data import script. I'm not savvy enough with MySQL to figure out what that is, though.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Foreign key constraint error - cannot seem to resolve this

This forum was archived on 2017-11-26.