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: constraint violation
Pages: [1]

Author Topic: DB Error: constraint violation  (Read 898 times)

wexzone

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 0
DB Error: constraint violation
January 10, 2011, 09:32:56 am
I am getting a DB Error: constraint violation when I try and edit a contact record:

Code: [Select]
Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`ecotouri_civicrm/civicrm_value_additional_membership_questions_9`, CONSTRAINT `FK_civicrm_value_additional_members_f8f4848ee168bf38` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_membership` ), 1452
Additional Details:

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

    [code] => -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_value_additional_membership_questions_9  ( do_you_want_your_member_profile__24,i_agree_to_ties_code_of_conduct_23,entity_id ) VALUES ( 1,1,118 ) ON DUPLICATE KEY UPDATE do_you_want_your_member_profile__24 = 1,i_agree_to_ties_code_of_conduct_23 = 1 [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`ecotouri_civicrm/civicrm_value_additional_membership_questions_9`, CONSTRAINT `FK_civicrm_value_additional_members_f8f4848ee168bf38` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_membership` )]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_value_additional_membership_questions_9  ( do_you_want_your_member_profile__24,i_agree_to_ties_code_of_conduct_23,entity_id ) VALUES ( 1,1,118 ) ON DUPLICATE KEY UPDATE do_you_want_your_member_profile__24 = 1,i_agree_to_ties_code_of_conduct_23 = 1 [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`ecotouri_civicrm/civicrm_value_additional_membership_questions_9`, CONSTRAINT `FK_civicrm_value_additional_members_f8f4848ee168bf38` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_membership` )]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_value_additional_membership_questions_9  ( do_you_want_your_member_profile__24,i_agree_to_ties_code_of_conduct_23,entity_id ) VALUES ( 1,1,118 ) ON DUPLICATE KEY UPDATE do_you_want_your_member_profile__24 = 1,i_agree_to_ties_code_of_conduct_23 = 1 [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`ecotouri_civicrm/civicrm_value_additional_membership_questions_9`, CONSTRAINT `FK_civicrm_value_additional_members_f8f4848ee168bf38` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_membership` )]"]
)

I have emptied the caches, logged out, logged back in, and still no luck.

Any suggestions?
« Last Edit: January 10, 2011, 10:20:24 am by wexzone »

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation
January 10, 2011, 10:31:36 am
Seems to be a foreign key constraint problem with regards to a membership record. Did you delete any membership records? Or membership types?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

wexzone

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 0
Re: DB Error: constraint violation
January 10, 2011, 10:44:58 am
no, I haven't deleted anything.

I was looking at the SQL table for these fields, and it asks for a entity_id, which I assume is the contact id.  In phpMyAdmin, it only allows a drop down box that goes from -27 to +27.

So, I guess that field is not set up correctly, cause nearly all of the contact IDs are bigger than 27.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation
January 10, 2011, 10:47:48 am
entity_id in this case appears to refer to memberships actually. See this from your error:

CONSTRAINT `FK_civicrm_value_additional_members_f8f4848ee168bf38` FOREIGN KEY (`entity_id`) REFERENCES `civicrm_membership` )]

The field entity_id seems to reference an id in the table civicrm_membership.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

wexzone

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 0
Re: DB Error: constraint violation
January 10, 2011, 10:53:06 am
the value being passed for entity id from the form is the contact  id.

I went ahead and re-created these custom fields, and it seems to be working, now.  Something must have messed up when we originally created it.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation
January 10, 2011, 10:54:41 am
OK. Glad you got it fixed.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

wexzone

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 0
Re: DB Error: constraint violation
January 10, 2011, 11:33:40 am
Ok, now I can't delete the old custom field sets....  I don't get an error or anything, but when I try and delete, nothing happens.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation
January 10, 2011, 12:07:38 pm
I do not know what might be the reason you can't delete. I could guess that it's still a FK constraint issue.

You wrote:

> the value being passed for entity id from the form is the contact  id.

Your original error was when editing contact id #118 ?
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

wexzone

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 0
Re: DB Error: constraint violation
January 10, 2011, 02:57:01 pm
Yes, it was editing contact 118.

It is strange, cause I created a few test custom fields sets, and none of them can be deleted.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: DB Error: constraint violation
January 11, 2011, 02:13:48 am
I don't know. I would suggest you start a new thread with all details of this issue and hopefully someone else will have some ideas.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • DB Error: constraint violation

This forum was archived on 2017-11-26.