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) »
  • Eeek, FK constraint errors
Pages: [1]

Author Topic: Eeek, FK constraint errors  (Read 1303 times)

robinhood

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 6
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.56
  • PHP version: 5.3.5
Eeek, FK constraint errors
December 20, 2008, 05:18:31 am
I posted previously about errors appearing in civimail here: http://forum.civicrm.org/index.php/topic,5940.0.html and thought that the problem was solved.  The problem with civimail was solved but now I have a new error when deleting a contact.

Quote
    Sorry. A non-recoverable error has occurred.

    DB Error: constraint violation

    Return to home page.

Error Details:

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

       
Code: [Select]
=> -3
    [message] => DB Error: constraint violation
    [mode] => 16
    [debug_info] => DELETE FROM civicrm_contact  WHERE (  civicrm_contact.id = 1660 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`mydb/civicrm_individual`, CONSTRAINT `FK_civicrm_individual_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
    [type] => DB_Error
    [user_info] => DELETE FROM civicrm_contact  WHERE (  civicrm_contact.id = 1660 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`mydb/civicrm_individual`, CONSTRAINT `FK_civicrm_individual_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="DELETE FROM civicrm_contact  WHERE (  civicrm_contact.id = 1660 )  [nativecode=1451 ** Cannot delete or update a parent row: a foreign key constraint fails (`mydb/civicrm_individual`, CONSTRAINT `FK_civicrm_individual_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`))]"]
)

To find the specific errors I entered this query:
Code: [Select]
SELECT civicrm_individual.first_name, civicrm_individual.last_name, civicrm_individual.id
FROM civicrm_individual
LEFT JOIN civicrm_contact ON ( civicrm_individual.contact_id = civicrm_contact.id )
WHERE civicrm_individual.id IS NOT NULL
AND civicrm_contact.id IS NULL;
... and found 114 rows in the civicrm_individual table with no corresponding row in the civicrm_contact table.  My questions are,
1.  How does that happen?
2.  Can I just recreate the missing 114 civicm_contact rows to match the civicrm_individual table or will I hit other constraints and/or inconsistencies?
3.  Is there some better method to fix it?

Thanks for any assistance.

Edit: oh, and 6 households and 74 organizations, too!
« Last Edit: December 20, 2008, 05:36:49 am by robinhood »

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: Eeek, FK constraint errors
December 20, 2008, 05:39:04 am
Your forum profile shows you are using CiviCRM 2.1.1 so,

Quote
SELECT civicrm_individual.first_name, civicrm_individual.last_name, civicrm_individual.id
FROM civicrm_individual
LEFT JOIN civicrm_contact ON ( civicrm_individual.contact_id = civicrm_contact.id )
WHERE civicrm_individual.id IS NOT NULL
AND civicrm_contact.id IS NULL;

This query should fail, since there is not civicrm_individual table does not exits. Are you using CiviCRM v1.x

Kurund
Found this reply helpful? Support CiviCRM

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: Eeek, FK constraint errors
December 20, 2008, 05:39:44 am
The civicrm_individual table should not exist in db's >= v2.0

not sure how it exists in your db/schema. We dropped the table in the upgrade for 2.0 (in case u upgraded)

there will be a difference betwen the two table (contact and individual) since the latter is not updated

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

robinhood

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 6
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.56
  • PHP version: 5.3.5
Re: Eeek, FK constraint errors
December 20, 2008, 06:21:03 am
So maybe I just carried over old tables when I reloaded the DB.  Don't know how.  Working with a backup copy, I dropped civicrm_individual, civicrm_household and civicrm_organization, and now a contact delete does not produce the error.  Will investigate further to see if any other old stuff is hanging around. 

Is there a handy list of tables that got dropped between 1.x and 2.x in your documentation somewhere?

Many 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: Eeek, FK constraint errors
December 20, 2008, 06:36:09 am
Quote
Is there a handy list of tables that got dropped between 1.x and 2.x in your documentation somewhere?
You might want to check "Schema redesign" section on http://wiki.civicrm.org/confluence/display/CRM/CiviCRM+v2.0

Kurund
Found this reply helpful? Support CiviCRM

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

This forum was archived on 2017-11-26.