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 »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Cannot upgrade from 3.1.5 to 3.2- FOREIGN KEY constraint fails
Pages: [1]

Author Topic: Cannot upgrade from 3.1.5 to 3.2- FOREIGN KEY constraint fails  (Read 1196 times)

jords

  • I’m new here
  • *
  • Posts: 15
  • Karma: 1
Cannot upgrade from 3.1.5 to 3.2- FOREIGN KEY constraint fails
July 30, 2010, 07:27:51 pm
Hi

I'm trying to upgrade my 3.1.5 site to 3.2, and the upgrade process failed with:

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_uf_field
   ( uf_group_id, field_name, is_required, is_reserved, weight, visibility, in_selector, is_searchable, location_type_id, label,field_type ) VALUES
   ( @uf_group_id_summary,           'phone' ,1,        0, 1,     'User and User Admin Only',   0,   0, 1,   'Home Phone', 'Contact'),
   ( @uf_group_id_summary,           'phone' ,1,      0, 2,     'User and User Admin Only',   0,      0, 2,   'Home Mobile', 'Contact' ),
   ( @uf_group_id_summary, 'street_address',   1,    0, 3,   'User and User Admin Only',   0,   0, NULL,    'Primary Address',         'Contact' ),
   ( @uf_group_id_summary, 'city',   1,    0, 4,   'User and User Admin Only',   0,   0, NULL,    'City',  'Contact' ),
   ( @uf_group_id_summary, 'state_province',   1,    0, 5,   'User and User Admin Only',   0,   0, NULL,    'State',  'Contact' ),
   ( @uf_group_id_summary, 'postal_code',   1,    0, 6,   'User and User Admin Only',   0,   0, NULL,    'Postal Code',  'Contact' ),
   ( @uf_group_id_summary, 'email',   1,    0, 7,   'User and User Admin Only',   0,   0, NULL,    'Primary Email',  'Contact' ),
   ( @uf_group_id_summary, 'group',   1,    0, 8,   'User and User Admin Only',   0,   0, NULL,    'Groups',  'Contact' ),
   ( @uf_group_id_summary, 'tag',   1,    0, 9,   'User and User Admin Only',   0,   0,      NULL,    'Tags', 'Contact' ),
   ( @uf_group_id_summary,           'gender',    1,         0,  10,  'User and User Admin Only',   0,    0,  NULL,  'Gender',  'Individual' ),
   ( @uf_group_id_summary,      'birth_date',   1,         0, 11, 'User and User Admin Only',   0,   0, NULL,   'Date of Birth',     'Individual' ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_uf_field`, CONSTRAINT `FK_civicrm_uf_field_location_type_id` FOREIGN KEY (`location_type_id`) REFERENCES `civicrm_location_type` (`id`) ON DELETE SET NULL)]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_uf_field
   ( uf_group_id, field_name, is_required, is_reserved, weight, visibility, in_selector, is_searchable, location_type_id, label,field_type ) VALUES
   ( @uf_group_id_summary,           'phone' ,1,        0, 1,     'User and User Admin Only',   0,   0, 1,   'Home Phone', 'Contact'),
   ( @uf_group_id_summary,           'phone' ,1,      0, 2,     'User and User Admin Only',   0,      0, 2,   'Home Mobile', 'Contact' ),
   ( @uf_group_id_summary, 'street_address',   1,    0, 3,   'User and User Admin Only',   0,   0, NULL,    'Primary Address',         'Contact' ),
   ( @uf_group_id_summary, 'city',   1,    0, 4,   'User and User Admin Only',   0,   0, NULL,    'City',  'Contact' ),
   ( @uf_group_id_summary, 'state_province',   1,    0, 5,   'User and User Admin Only',   0,   0, NULL,    'State',  'Contact' ),
   ( @uf_group_id_summary, 'postal_code',   1,    0, 6,   'User and User Admin Only',   0,   0, NULL,    'Postal Code',  'Contact' ),
   ( @uf_group_id_summary, 'email',   1,    0, 7,   'User and User Admin Only',   0,   0, NULL,    'Primary Email',  'Contact' ),
   ( @uf_group_id_summary, 'group',   1,    0, 8,   'User and User Admin Only',   0,   0, NULL,    'Groups',  'Contact' ),
   ( @uf_group_id_summary, 'tag',   1,    0, 9,   'User and User Admin Only',   0,   0,      NULL,    'Tags', 'Contact' ),
   ( @uf_group_id_summary,           'gender',    1,         0,  10,  'User and User Admin Only',   0,    0,  NULL,  'Gender',  'Individual' ),
   ( @uf_group_id_summary,      'birth_date',   1,         0, 11, 'User and User Admin Only',   0,   0, NULL,   'Date of Birth',     'Individual' ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_uf_field`, CONSTRAINT `FK_civicrm_uf_field_location_type_id` FOREIGN KEY (`location_type_id`) REFERENCES `civicrm_location_type` (`id`) ON DELETE SET NULL)]
    [to_string] => [db_error: message="DB Error: constraint violation" code=-3 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_uf_field
   ( uf_group_id, field_name, is_required, is_reserved, weight, visibility, in_selector, is_searchable, location_type_id, label,field_type ) VALUES
   ( @uf_group_id_summary,           'phone' ,1,        0, 1,     'User and User Admin Only',   0,   0, 1,   'Home Phone', 'Contact'),
   ( @uf_group_id_summary,           'phone' ,1,      0, 2,     'User and User Admin Only',   0,      0, 2,   'Home Mobile', 'Contact' ),
   ( @uf_group_id_summary, 'street_address',   1,    0, 3,   'User and User Admin Only',   0,   0, NULL,    'Primary Address',         'Contact' ),
   ( @uf_group_id_summary, 'city',   1,    0, 4,   'User and User Admin Only',   0,   0, NULL,    'City',  'Contact' ),
   ( @uf_group_id_summary, 'state_province',   1,    0, 5,   'User and User Admin Only',   0,   0, NULL,    'State',  'Contact' ),
   ( @uf_group_id_summary, 'postal_code',   1,    0, 6,   'User and User Admin Only',   0,   0, NULL,    'Postal Code',  'Contact' ),
   ( @uf_group_id_summary, 'email',   1,    0, 7,   'User and User Admin Only',   0,   0, NULL,    'Primary Email',  'Contact' ),
   ( @uf_group_id_summary, 'group',   1,    0, 8,   'User and User Admin Only',   0,   0, NULL,    'Groups',  'Contact' ),
   ( @uf_group_id_summary, 'tag',   1,    0, 9,   'User and User Admin Only',   0,   0,      NULL,    'Tags', 'Contact' ),
   ( @uf_group_id_summary,           'gender',    1,         0,  10,  'User and User Admin Only',   0,    0,  NULL,  'Gender',  'Individual' ),
   ( @uf_group_id_summary,      'birth_date',   1,         0, 11, 'User and User Admin Only',   0,   0, NULL,   'Date of Birth',     'Individual' ) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_uf_field`, CONSTRAINT `FK_civicrm_uf_field_location_type_id` FOREIGN KEY (`location_type_id`) REFERENCES `civicrm_location_type` (`id`) ON DELETE SET NULL)]"]
)

It is trying to insert a row with location_type_id 2, but the rows in my civicrm_location_type table are:
1-home
3-old
4-work
5-billing

dlobo mentioned that this is likely a bug in civiCRM?

Thanks
Jordan[/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: Cannot upgrade from 3.1.5 to 3.2- FOREIGN KEY constraint fails
July 30, 2010, 07:39:02 pm

it looks like for phone mobile we are using location type id = 2 rather than using phone_type_id in the upgrade script. we should fix this (IMO)

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

jords

  • I’m new here
  • *
  • Posts: 15
  • Karma: 1
Re: Cannot upgrade from 3.1.5 to 3.2- FOREIGN KEY constraint fails
July 30, 2010, 08:00:02 pm
I might go find the script and fix it in order to get my site running

EDIT: Great Success! edited CRM/Upgrade/Incremental/sql/3.2.beta3.mysql.tpl and beta4 to have the home mobile inserted with location type = 1 (cheap hack :) and it appears to have worked, upgrade finished at least.
« Last Edit: July 30, 2010, 08:16:38 pm by jords »

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: Cannot upgrade from 3.1.5 to 3.2- FOREIGN KEY constraint fails
August 02, 2010, 11:11:53 pm
I think instead of hardcoding we should juts pick default site location type. We should not change location type to phone type.

Kurund
Found this reply helpful? Support CiviCRM

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Cannot upgrade from 3.1.5 to 3.2- FOREIGN KEY constraint fails

This forum was archived on 2017-11-26.