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 Drupal Modules (Moderator: Donald Lobo) »
  • a foreign key constraint fails when saving Drupal user profile
Pages: [1]

Author Topic: a foreign key constraint fails when saving Drupal user profile  (Read 5575 times)

linkx

  • I post occasionally
  • **
  • Posts: 86
  • Karma: 7
a foreign key constraint fails when saving Drupal user profile
August 03, 2009, 03:34:27 pm
I created a CiviCRM profile called "Website User Profile", enabled "User Registration, View/Edit User Account", and created 12 new Drupal user accounts, filling out the CiviCRM Profile fields for each user during the drupal account creation.

Then, after playing around editing many things in the CiviCRM profile settings, I begin to see the following error when logging in with any of the 12 users:

Code: [Select]
DB Error: constraint violation

Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`[databasename]_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE), 1452

This error also occurs when updating or editing a user profile.

It does NOT occur when I create a new account. It seems like the when profile was changed it messed up recorded data for the 12 users that I created before changing the profile.

Please let me know if you have any suggestions. Thanks!

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: a foreign key constraint fails when saving Drupal user profile
August 03, 2009, 08:04:40 pm
Can you give more details about your install. CiviCRM version ?

Kurund
Found this reply helpful? Support CiviCRM

linkx

  • I post occasionally
  • **
  • Posts: 86
  • Karma: 7
Re: a foreign key constraint fails when saving Drupal user profile
August 04, 2009, 08:42:30 am
CiviCRM 2.2.7 fresh install on Drupal 6.13 with the views shared tables array in settings.php

Here is the rest of the error:

Code: [Select]
Error Details:

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

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 15 ,  1 ,  20090804114026 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`[databasename]_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 15 ,  1 ,  20090804114026 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`[databasename]_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`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 INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 15 ,  1 ,  20090804114026 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`[databasename]_civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]"]
)


I can fix the issue by deleting and re-creating all the records, but there must be another way . . . [/code]
« Last Edit: August 04, 2009, 08:44:39 am by linkx »

linkx

  • I post occasionally
  • **
  • Posts: 86
  • Karma: 7
Re: a foreign key constraint fails when saving Drupal user profile
August 04, 2009, 09:31:23 am
I discovered that this error only occurs with users that were members of a group that was deleted.

Does this spark any ideas on how to fix?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: a foreign key constraint fails when saving Drupal user profile
August 04, 2009, 10:55:44 am
Sounds like this "misbehavior" might be caused by a combination of group(s) being deleted AND a CiviCRM-related module (e.g. CivCRM Group Roles etc.).

In order to narrow this down, you should:
* recreate the error on your site
* then disable all CiviCRM RELATED modules (but not CiviCRM) and see if that makes the error go away (I suspect it will)
* then re-enable the related modules one at a time to see which one causes the error to reappear
* finally - if you narrow it down AND it's a module we include in our distribution - file an issue tracker report w/ details on steps to recreate
Protect your investment in CiviCRM by  becoming a Member!

linkx

  • I post occasionally
  • **
  • Posts: 86
  • Karma: 7
Re: a foreign key constraint fails when saving Drupal user profile
August 04, 2009, 11:58:40 am
Bygolly Dave you are right. It all makes sense now. I had enabled CiviGroup Roles Sync and mapped a Drupal role to a CiviCRM group. When I deleted the group from CiviCRM, I did not go back and delete the Drupal mapping in CiviGroup Roles Sync. So users who belonged to that CiviCRM group got the error when viewing/editing their Drupal profile.

Removed the group-to-role mapping and now the error is gone.

Thanks for your time and your effective suggestions.

Link

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: a foreign key constraint fails when saving Drupal user profile
August 04, 2009, 02:28:27 pm
This is a bug in CiviGroup Roles Synch IMO (it should delete or disable the mapping if the CiviCRM group is deleted). Can you file an issue (preferably with a patch).
Protect your investment in CiviCRM by  becoming a Member!

MickC

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.0
  • PHP version: 5.0
Re: a foreign key constraint fails when saving Drupal user profile
February 19, 2011, 07:49:57 am
Hi - I wonder if you guys could help - I'm really struggling with a multisite installation - the 2nd domain is getting this error but no the first.
I've deleted all the groups in "Manage ACL Roles" except Administrator and Authenticated and still I get the same error.  Any ideas? Thanks

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: a foreign key constraint fails when saving Drupal user profile
February 19, 2011, 11:30:12 am
Suggest you start a new thread and post exact steps and complete error message. The prior poster had an issue specifically related to the CiviCRM Group Roles add-on module (which you didn't mention using).
Protect your investment in CiviCRM by  becoming a Member!

MickC

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 3.3
  • CMS version: Drupal 6.20
  • MySQL version: 5.0
  • PHP version: 5.0
Re: a foreign key constraint fails when saving Drupal user profile
March 31, 2011, 07:16:34 am
Hi Dave - I did post a new topic some time back but no response.

http://forum.civicrm.org/index.php/topic,18681.msg77620.html#msg77620

I may have used the group roles feature at some point, but it's all disabled, and I've removed all roles - still get the error.
Also cannot send mail.

Considering reinstalling which is pretty drastic - any ideas welcome.

Thanks,

MC

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: a foreign key constraint fails when saving Drupal user profile
March 31, 2011, 03:00:47 pm
Mick - Haven't installed Group Roles module for a while, but taking a quick look at the code it looks like that module creates a new table that joins CiviCRM groups to Drupal roles - civicrm_group_roles_rules. I'm guessing that table still exists and is pointing to a non-existent entry in the civicrm_group table (with id = 2).

Code: [Select]
// from civicrm_group_roles.install
function civicrm_group_roles_schema( )
{
    $schema['civicrm_group_roles_rules'] = array(
                                                 'fields' => array(
                                                                   'id' => array(
                                                                                 'type' => 'serial',
                                                                                 'unsigned' => TRUE,
                                                                                 'not null' => TRUE,
                                                                                 ),
                                                                   'role_id' => array(
                                                                                      'type' => 'int',
                                                                                      'unsigned' => TRUE,
                                                                                      'not null' => TRUE,
                                                                                      ),
                                                                   'group_id' => array(
                                                                                       'type' => 'int',
                                                                                       'unsigned' => TRUE,
                                                                                       'not null' => TRUE,
                                                                                       )
                                                                   ),
                                                 'primary key' => array('id'),
                                                 );
   
    return $schema;
}
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • a foreign key constraint fails when saving Drupal user profile

This forum was archived on 2017-11-26.