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 error on import of civicrm_generated.mysql data file
Pages: [1]

Author Topic: foreign key error on import of civicrm_generated.mysql data file  (Read 5769 times)

twelch

  • Guest
foreign key error on import of civicrm_generated.mysql data file
June 06, 2007, 02:57:49 pm
Hi, I've tried this a few times now, brand new database, the structure file goes in just fine, but I get the following foreign key error when I try to import the sample data. The usual fix is to set the domain ID to 1. It already is here, so that isn't the problem.

Code: [Select]
Error

SQL query:

INSERT INTO `civicrm_acl` ( `id` , `domain_id` , `name` , `deny` , `entity_table` , `entity_id` , `operation` , `object_table` , `object_id` , `acl_table` , `acl_id` , `is_active` )
VALUES ( 1, 1, 'Edit All Contacts', 0, 'civicrm_acl_role', 1, 'Edit', 'civicrm_saved_search', 0, NULL , NULL , 1 ) ;

MySQL said: Documentation
#1216 - Cannot add or update a child row: a foreign key constraint fails

Any ideas?

Thanks,
Troy

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 error on import of civicrm_generated.mysql data file
June 06, 2007, 03:07:35 pm

what version of mysql are u using? if its a 4.0.x version, u might want to consider upgrading to 5.x

the sql file does instruct mysql to disable FK checks when loading the file (in a comment). Some versions of mysql ignore  that comment and hence the FK error

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

twelch

  • Guest
Re: foreign key error on import of civicrm_generated.mysql data file
June 06, 2007, 03:37:22 pm
Hi, the mysql version is 4.1.21 and I'm using a provider so I can't really do anything about the version. If the DB ignores the FK command, what do i do about getting the data in. I have also tried using the civicrm_data.mysql file instead, but then I get FK errors when I try to import the drupal users.

Thanks,
Troy

schnuckovic

  • Guest
Re: foreign key error on import of civicrm_generated.mysql data file
July 04, 2007, 12:20:57 pm
Has this been fixed?
I seem to have the same issue.

Loading the civicrm_generated.mysql works, but then I can't delete the dummy users.
When loading the civicrm_data.mysql, I can't import the drupal users nor can I add new individuals. Results always in key constraint errors.

1.7.9821 Drupal PHP5,
MySQL database   5.0.32
PHP   5.2.0-8+etch4, yes, Debian!
Drupal 5.1

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: foreign key error on import of civicrm_generated.mysql data file
July 05, 2007, 12:06:38 am
Quote from: twelch on June 06, 2007, 02:57:49 pm
Code: [Select]
INSERT INTO `civicrm_acl` ( `id` , `domain_id` , `name` , `deny` , `entity_table` , `entity_id` , `operation` , `object_table` , `object_id` , `acl_table` , `acl_id` , `is_active` )
VALUES ( 1, 1, 'Edit All Contacts', 0, 'civicrm_acl_role', 1, 'Edit', 'civicrm_saved_search', 0, NULL , NULL , 1 ) ;

MySQL said: Documentation #1216 - Cannot add or update a child row: a foreign key constraint fails

The only foreign key in this table is the domain_id column (to civicrm_domain.id), so if it throws the above error then you most probably don’t have an entry in civicrm_domain with id of 1. Can you double-check whether you do have such an entry?

Quote from: twelch on June 06, 2007, 03:37:22 pm
If the DB ignores the FK command, what do i do about getting the data in.

Uncomment the lines that change the FOREIGN_KEY_CHECKS, so they look like this:

Code: [Select]
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
…
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;

Quote from: twelch on June 06, 2007, 03:37:22 pm
I have also tried using the civicrm_data.mysql file instead, but then I get FK errors when I try to import the drupal users.

What errors? What were the exact steps you took?
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: foreign key error on import of civicrm_generated.mysql data file
July 05, 2007, 12:08:37 am
Quote from: schnuckovic on July 04, 2007, 12:20:57 pm
Loading the civicrm_generated.mysql works, but then I can't delete the dummy users.
When loading the civicrm_data.mysql, I can't import the drupal users nor can I add new individuals. Results always in key constraint errors.

Can you please post the error messages?
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

schnuckovic

  • Guest
Re: foreign key error on import of civicrm_generated.mysql data file
July 05, 2007, 01:20:59 pm
When I do:
mysql -u civicrm_user -h civicrm_db_server -pcivicrm_password civicrm_db < civicrm_41.mysql
mysql -u civicrm_user -h civicrm_db_server -pcivicrm_password civicrm_db < civicrm_data.mysql

and then try to synchronize the drupal users I get:

Code: [Select]
Synchronize Users-to-Contacts

unrecoverable error
    Sorry. A non-recoverable error has occurred.

    Return to CiviCRM menu.

Error Details:

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

    [code] => -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_log (entity_table , entity_id , modified_id , modified_date ) VALUES ('civicrm_contact' ,  1 ,  102 ,  20070705221305 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`))]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_log (entity_table , entity_id , modified_id , modified_date ) VALUES ('civicrm_contact' ,  1 ,  102 ,  20070705221305 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`))]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_log (entity_table , entity_id , modified_id , modified_date ) VALUES ('civicrm_contact' ,  1 ,  102 ,  20070705221305 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`))]"]
)


Then I try to create an individual and get:

Code: [Select]
New Individual

unrecoverable error
    Sorry. A non-recoverable error has occurred.

    Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`)), 1452

    Return to CiviCRM menu.

Error Details:

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

    [code] => -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_log (entity_table , entity_id , modified_id , modified_date ) VALUES ('civicrm_contact' ,  2 ,  102 ,  20070705221623 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`))]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_log (entity_table , entity_id , modified_id , modified_date ) VALUES ('civicrm_contact' ,  2 ,  102 ,  20070705221623 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`))]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_log (entity_table , entity_id , modified_id , modified_date ) VALUES ('civicrm_contact' ,  2 ,  102 ,  20070705221623 )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_log`, CONSTRAINT `FK_civicrm_log_modified_id` FOREIGN KEY (`modified_id`) REFERENCES `civicrm_contact` (`id`))]"]
)

When I do:
mysql -u civicrm_user -h civicrm_db_server -pcivicrm_password civicrm_db < civicrm_41.mysql
mysql -u civicrm_user -h civicrm_db_server -pcivicrm_password civicrm_db < civicrm_generated.mysql

And try to synchronize the drupal users, everything works fine.

But when I try to delete all (dummy) users, it asks me if I really want to delete the 105 contacts (102 from generated + the ones I have setup in drupal). I say yes and get:

Code: [Select]
Find Contacts

unrecoverable error
    Sorry. A non-recoverable error has occurred.

    Database Error Code: Cannot delete or update a parent row: a foreign key constraint fails (`civicrm/civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`)), 1451

    Return to CiviCRM menu.

Error Details:

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

    [code] => -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] => DELETE FROM civicrm_contact  WHERE (  civicrm_contact.id = 76 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`civicrm/civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
    [type] => DB_Error
    [user_info] => DELETE FROM civicrm_contact  WHERE (  civicrm_contact.id = 76 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`civicrm/civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="DELETE FROM civicrm_contact  WHERE (  civicrm_contact.id = 76 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`civicrm/civicrm_participant`, CONSTRAINT `FK_civicrm_participant_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]"]
)


Your help is well appreciated.[/code][/code][/code]

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 error on import of civicrm_generated.mysql data file
July 05, 2007, 02:20:37 pm

1. To fix the first issue, you need to reset your drupal session table whenever u reload the civicrm database. One way of doing this is explained here:

http://wiki.civicrm.org/confluence/display/CRMDOC/Upgrading+Drupal+Sites+from+v1.6+to+v1.7#UpgradingDrupalSitesfromv1.6tov1.7-9.ResetYourUserSessionandCleanupTemplateCache

2. To fix the second issue, please enable the CiviMember and CiviEvent component in administer civicrm >> global settings >> enable components. You will not need to do this in v1.8 onwards

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

schnuckovic

  • Guest
Re: foreign key error on import of civicrm_generated.mysql data file
July 07, 2007, 12:27:52 am
Thanks for your suggestions, however, it didn't work.

Resetting the drupal session table didn't have any effect. And the second, both modules were actually enabled.

I gave 1.8 alpha a try and found the 'generated' working. Loading 'data' only didn't allow me to import the drupal users. With 'generated' I was able to delete the dummy users and import the drupalers.

I think I can go from here, thanks again.


Schnuckovic

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • foreign key error on import of civicrm_generated.mysql data file

This forum was archived on 2017-11-26.