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) »
  • DB Error: constraint violation on login. Civi 3.1/Drupal 6
Pages: [1]

Author Topic: DB Error: constraint violation on login. Civi 3.1/Drupal 6  (Read 3661 times)

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
DB Error: constraint violation on login. Civi 3.1/Drupal 6
July 22, 2010, 11:28:31 pm
Hi all,
This error is related to the civicrm_subscription_history table and it appears that on login for several but not all Drupal users. There are only 2 groups but it appears to try to do an insert for a group #6

Here's the error from one login
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 ( 51 ,  6 ,  20100723011246 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`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 ( 51 ,  6 ,  20100723011246 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`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 ( 51 ,  6 ,  20100723011246 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]"]
)


Here's another
Code: [Select]
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 ( 1 ,  6 ,  20100723012615 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`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 ( 1 ,  6 ,  20100723012615 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`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 ( 1 ,  6 ,  20100723012615 , 'API' , 'Added' )  [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_subscription_history`, CONSTRAINT `FK_civicrm_subscription_history_group_id` FOREIGN KEY (`group_id`) REFERENCES `civicrm_group` (`id`) ON DELETE CASCADE)]"]
)

I'm not sure why it would be referencing a group with an id of 6 because as far as I know we've only had 2 groups.... Administrators and a Test Group.

Any thoughts?

Thanks,[/code][/code]
My CiviCRM Extension Workshop: https://github.com/awasson

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: DB Error: constraint violation on login. Civi 3.1/Drupal 6
July 22, 2010, 11:45:19 pm

check if u have enabled some other drupal/civicrm modules (civicrm_group_roles maybe?)

seems like there is some old data in those tables

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

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
July 22, 2010, 11:49:00 pm
Oh, you're absolutely right... We enabled groups/synch and I'll be someone mapped it and then deleted the groups they made. I'll check that out.

Thanks!
My CiviCRM Extension Workshop: https://github.com/awasson

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
July 23, 2010, 12:02:10 am
Yup, that was it... Thanks!

PS: I'm still planning to pursue and document the TAX mod.... I've just been swamped with other configuration issues.
My CiviCRM Extension Workshop: https://github.com/awasson

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
April 15, 2011, 06:57:21 am
We seem to have run into the same sort of trouble, reported here: http://forum.civicrm.org/index.php/topic,19427.msg80863.html

I tried turning off the "CiviMember Roles Sync" mod, same error. Was it necessary to do more than merely disable that mod?

The mod does not seem to support granularity of syncing for only certain Civi contact types... Members and not Organizations. If disabling the mod had corrected this error, I would have been inclined to try hacking the mod to only sync when the ID was a member ID. As-is, I can not be sure this really is what is happening.

Suggestions please?
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
April 15, 2011, 09:24:27 am
That was such a long time ago that I don't recall exactly what I need to do to fix the issue.

I think what had happened is that someone created a group and then mapped a civiCRM membership type to that group early on in the project. Later on that group was removed but the mapping of the member type was still intact and civiCRM/Drupal was trying to insert data into a table that didn't exist. Or something like that.

To fix it I probably went in to Administer -> Custom -> Custom Data  and made sure that there was no custom data fields or custom data groups that were broken.

Then I would have cleared all of the caches. You can do that via Drupal's Site Configuration -> Performance  (your-site/admin/settings/performance).

I hope that sheds some light.
My CiviCRM Extension Workshop: https://github.com/awasson

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
April 15, 2011, 11:23:33 am
awasson: You did not have some Civi contacts that had no corresponding Drupal account in your case?

I verified the Civi Custom Data fields. All (3) are working properly and are really needed. Two custom fields are specifically for these Organization records in Civi that do not have corresponding Drupal ID's. The last custom field is associated with Members and that Civi type does have corresponding Drupal ID's.
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
April 15, 2011, 04:41:38 pm
No, I believe the problem was that I had a civiCRM member type that referenced a data group field that didn't exist.

* Long time ago so I'm not really sure what it was all about.

The important bit of the error notice is below... civi was trying to insert a value for group_id = 6 and there was no group_id that matched 6. There was at one time but it was removed. So I think a custom data group or custom data field was referencing group_id 6.

[debug_info] => INSERT INTO civicrm_subscription_history (contact_id , group_id , date , method , status ) VALUES ( 51 ,  6 ,  20100723011246 , 'API' , 'Added' )

What sort of error are you getting?
My CiviCRM Extension Workshop: https://github.com/awasson

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
April 15, 2011, 06:17:40 pm
awasson: Lobo was able to quickly figure out what was going on. I guess a handful of our contact records mysteriously ended up with contact_sub_type data, which was causing the same type of error that you had reported here.

<dlobo>   so the mystery is how/why did the db have contact_sub_type set to people's names
<dlobo>   that was causing our code to do the wrong thing (bug)
<dlobo>   and we were not reporting it nicely
<dlobo>   i'll file an issue and fix for 3.4
<dlobo>   so future folks dont spend forever on this

We really are not using contact_sub_type capabilities, and him NULLing that column cleared up the troubles. Glad it was not the "CiviMember Roles Sync" mod causing the troubles!
« Last Edit: April 15, 2011, 06:23:12 pm by mdlueck »
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

awasson

  • I post frequently
  • ***
  • Posts: 230
  • Karma: 7
  • Living in a world of Drupal / CiviCRM
    • My Company: Luna Design
  • CiviCRM version: Latest
  • CMS version: Drupal 6/7/8
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
April 15, 2011, 07:24:37 pm
Oh great! Glad you were able to sort it out quickly.

Have a good weekend,
Andrew
My CiviCRM Extension Workshop: https://github.com/awasson

ZenLax

  • I’m new here
  • *
  • Posts: 19
  • Karma: 0
  • Not an engineer, but I play one on TV.
  • CiviCRM version: 4.8
  • CMS version: Drupal 6.x/7.x
  • MySQL version: 5.5
  • PHP version: 5.3
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
May 11, 2011, 09:02:23 pm
I am also having this same problem, which appeared immediately following a server migration (rather than clean install).

It appears whenever a user logs into the site, or when they create/edit their Drupal account. The site uses 2 custom profiles users must complete when creating a new Drupal account.

The site uses CiviMember and CiviRoles Group synch. I have not tried disabling them, based on the above comment.

We are about a week from going live, but this is a real show-stopper since users can't create an account without seeing a "Fatal Error: Database Constraint" message.

We are using Civi 3.2 and Drupal 6.2. I've attached the error log details to this post and would really, really appreciate some help debugging it!

Follow Up Note: When I first installed  Civi, it created the demo database. I then went in and deleted all those contacts/events/groups/etc.  Some of the deletions probably occurred after installing the OG Group synch module.
« Last Edit: May 12, 2011, 09:37:08 am by ZenLax »

mdlueck

  • Ask me questions
  • ****
  • Posts: 382
  • Karma: 4
  • CiviCRM version: 4.7.24
  • CMS version: Drupal 6.x
  • MySQL version: 5.5.54
  • PHP version: 5.3.10
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
May 12, 2011, 01:21:40 pm
@ZenLax: In our case, we finally tracked down what really happened... documented here: http://forum.civicrm.org/index.php/topic,19427.msg82371.html#msg82371

I just did not help that error handling in this area of code had been disabled to allow the automated test scripts to be allowed to work uninterrupted.
--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/

ZenLax

  • I’m new here
  • *
  • Posts: 19
  • Karma: 0
  • Not an engineer, but I play one on TV.
  • CiviCRM version: 4.8
  • CMS version: Drupal 6.x/7.x
  • MySQL version: 5.5
  • PHP version: 5.3
Re: DB Error: constraint violation on login. Civi 3.1/Drupal 6
May 24, 2011, 10:55:49 am
Follow Up: Case Solved. In the end, the "DB Error: constraint violation" problem turned out to be a simple Drupal Permissions issue, which were set incorrectly. Once the permissions were updated correctly, the error disappeared.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • DB Error: constraint violation on login. Civi 3.1/Drupal 6

This forum was archived on 2017-11-26.