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) »
  • Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
Pages: [1] 2

Author Topic: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id  (Read 7089 times)

eugeniafranzoni

  • Guest
Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
February 27, 2008, 12:24:07 pm
Hi,

while upgrading from 1.9.11960 to 2.0 I have an error. I have followed the instructions here:
http://wiki.civicrm.org/confluence/display/CRMDOC/Upgrade+Drupal+Sites+to+2.0

and have reconstructed the database from civicrm_41.mysql, but no luck.

The error I have is:

---
    Database Error Code: Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_activity`, CONSTRAINT `FK_civicrm_activity_activity_type_id` FOREIGN KEY (`activity_type_id`) REFERENCES `civicrm_option_value` (`id`)), 1452

    Return to home page.

Error Details:

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

       
Code: [Select]
=> -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] => INSERT INTO civicrm_activity (`source_contact_id`, `source_record_id`, `activity_type_id`, `subject`, `activity_date_time`, `due_date_time`, `duration`, `location`, `phone_id`, `phone_number`, `details`, `status_id`, `priority_id`, `parent_id`, `is_test`)
SELECT ah.entity_id, ah.activity_id, @ov_id_event, ah.activity_summary,
       ah.activity_date, NULL, NULL, NULL, NULL, NULL,
       ah.activity_summary, @ov_id_completed, NULL, NULL, ah.is_test
FROM civicrm_activity_history ah
WHERE ah.module IN ('CiviEvent')
GROUP BY ah.module, ah.entity_id [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_activity`, CONSTRAINT `FK_civicrm_activity_activity_type_id` FOREIGN KEY (`activity_type_id`) REFERENCES `civicrm_option_value` (`id`))]
    [type] => DB_Error
    [user_info] => INSERT INTO civicrm_activity (`source_contact_id`, `source_record_id`, `activity_type_id`, `subject`, `activity_date_time`, `due_date_time`, `duration`, `location`, `phone_id`, `phone_number`, `details`, `status_id`, `priority_id`, `parent_id`, `is_test`)
SELECT ah.entity_id, ah.activity_id, @ov_id_event, ah.activity_summary,
       ah.activity_date, NULL, NULL, NULL, NULL, NULL,
       ah.activity_summary, @ov_id_completed, NULL, NULL, ah.is_test
FROM civicrm_activity_history ah
WHERE ah.module IN ('CiviEvent')
GROUP BY ah.module, ah.entity_id [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_activity`, CONSTRAINT `FK_civicrm_activity_activity_type_id` FOREIGN KEY (`activity_type_id`) REFERENCES `civicrm_option_value` (`id`))]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO civicrm_activity (`source_contact_id`, `source_record_id`, `activity_type_id`, `subject`, `activity_date_time`, `due_date_time`, `duration`, `location`, `phone_id`, `phone_number`, `details`, `status_id`, `priority_id`, `parent_id`, `is_test`)
SELECT ah.entity_id, ah.activity_id, @ov_id_event, ah.activity_summary,
       ah.activity_date, NULL, NULL, NULL, NULL, NULL,
       ah.activity_summary, @ov_id_completed, NULL, NULL, ah.is_test
FROM civicrm_activity_history ah
WHERE ah.module IN ('CiviEvent')
GROUP BY ah.module, ah.entity_id [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm/civicrm_activity`, CONSTRAINT `FK_civicrm_activity_activity_type_id` FOREIGN KEY (`activity_type_id`) REFERENCES `civicrm_option_value` (`id`))]"]
)
---

I have looked in the forums and I realized I have done something like this guy:
http://forum.civicrm.org/index.php/topic,2499.0.html

i.e. I have deleted all of some standard options from CiviCRM (namely: all name suffixes for contacts, for in Italy we don't
use them). I have tried to recreate them but it gives the same error (so I'm not really sure that is the problem).

Does anybody have an idea of what's the problem and what can I do to solve that?

thanks

Eugenia

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: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
February 27, 2008, 12:29:44 pm

Can u try the new beta3 which was released a few hours ago. That FK relationship has been removed

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

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
February 29, 2008, 10:54:26 am
I am in process of upgrading my site from 1.9 to 2.0 beta 3. After pressing continue on the last step of upgrade process, I get a foreign key error as well.

Code: [Select]
backTrace

/var/www/html/sites/all/modules/civicrm/CRM/Core/Error.php, backtrace, 143
, handle,
/var/www/html/sites/all/modules/civicrm/packages/PEAR.php, call_user_func, 901
/var/www/html/sites/all/modules/civicrm/packages/DB.php, PEAR_Error, 888
/var/www/html/sites/all/modules/civicrm/packages/PEAR.php, DB_Error, 563
/var/www/html/sites/all/modules/civicrm/packages/DB/common.php, raiseError, 1849
/var/www/html/sites/all/modules/civicrm/packages/DB/mysql.php, raiseError, 894
/var/www/html/sites/all/modules/civicrm/packages/DB/mysql.php, mysqlRaiseError, 324
/var/www/html/sites/all/modules/civicrm/packages/DB/common.php, simpleQuery, 1162
/var/www/html/sites/all/modules/civicrm/packages/DB/DataObject.php, query, 2343
/var/www/html/sites/all/modules/civicrm/packages/DB/DataObject.php, _query, 1566
/var/www/html/sites/all/modules/civicrm/CRM/Core/DAO.php, query, 716
/var/www/html/sites/all/modules/civicrm/CRM/Upgrade/Form.php, executeQuery, 126
/var/www/html/sites/all/modules/civicrm/CRM/Upgrade/TwoZero/Form/Step5.php, runQuery, 175
/var/www/html/sites/all/modules/civicrm/CRM/Upgrade/Form.php, upgrade, 114
/var/www/html/sites/all/modules/civicrm/CRM/Core/StateMachine.php, postProcess, 166
/var/www/html/sites/all/modules/civicrm/CRM/Core/QuickForm/Action/Next.php, perform, 63
/var/www/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Controller.php, perform, 195
/var/www/html/sites/all/modules/civicrm/packages/HTML/QuickForm/Page.php, handle, 95
/var/www/html/sites/all/modules/civicrm/CRM/Core/Controller.php, handle, 223
/var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php, run, 203
/var/www/html/sites/all/modules/civicrm/CRM/Core/Invoke.php, upgrade, 150
/var/www/html/sites/all/modules/civicrm/drupal/civicrm.module, invoke, 329
, civicrm_invoke,
/var/www/html/includes/menu.inc, call_user_func_array, 418
/var/www/html/index.php, menu_execute_active_handler, 15

Code: [Select]
Error Details:

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

    [code] => -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] =>
INSERT INTO custom_value_1_File_Upload (domain_id,entity_id,Attachment)
SELECT 1, cv.entity_id, cv.char_data FROM civicrm_custom_value cv
WHERE cv.custom_field_id=2
ON DUPLICATE KEY UPDATE Attachment=cv.char_data [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm19Fix/custom_value_1_File_Upload`, CONSTRAINT `FK_custom_value_1_File_Upload_Attachment` FOREIGN KEY (`Attachment`) REFERENCES `civicrm_file` (`id`) ON DELETE SET NULL)]
    [type] => DB_Error
    [user_info] =>
INSERT INTO custom_value_1_File_Upload (domain_id,entity_id,Attachment)
SELECT 1, cv.entity_id, cv.char_data FROM civicrm_custom_value cv
WHERE cv.custom_field_id=2
ON DUPLICATE KEY UPDATE Attachment=cv.char_data [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm19Fix/custom_value_1_File_Upload`, CONSTRAINT `FK_custom_value_1_File_Upload_Attachment` FOREIGN KEY (`Attachment`) REFERENCES `civicrm_file` (`id`) ON DELETE SET NULL)]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="
INSERT INTO custom_value_1_File_Upload (domain_id,entity_id,Attachment)
SELECT 1, cv.entity_id, cv.char_data FROM civicrm_custom_value cv
WHERE cv.custom_field_id=2
ON DUPLICATE KEY UPDATE Attachment=cv.char_data [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm19Fix/custom_value_1_File_Upload`, CONSTRAINT `FK_custom_value_1_File_Upload_Attachment` FOREIGN KEY (`Attachment`) REFERENCES `civicrm_file` (`id`) ON DELETE SET NULL)]"]
)


Any ideas on how to resolve? Thanks much,
Emily[/code]
« Last Edit: February 29, 2008, 11:11:58 am by emilyf »

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: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
February 29, 2008, 03:39:45 pm

Can you please email your db to deepak at webaccess.co.in

most likely there is an inconsistency between your custom value table and file table in v1.9. we'll investigate and figure out whats happening and a potential fix

thanx

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

acrosman

  • Guest
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 03, 2008, 12:57:24 pm
Has there been any progress on this?  I'm also working on an update that's Drupal based and failing with Foreign key problems.  I rebuilt the database, which got me from step 2 to step 5, but now I'm hung up there:

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

    [code] => -1
    [message] => DB Error: unknown error
    [mode] => 16
    [debug_info] =>
INSERT INTO custom_value_11155_Test_Custom_Data_1 (domain_id,entity_id,Upload_a_file)
SELECT 11155, cv.entity_id, cv.char_data FROM civicrm_custom_value cv
WHERE cv.custom_field_id=5
ON DUPLICATE KEY UPDATE Upload_a_file=cv.char_data [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`sample_civicrm19fix/custom_value_11155_Test_Custom_Data_1`, CONSTRAINT `FK_custom_value_11155_Test_Custom_Data_1_Upload_a_file` FOREIGN KEY (`Upload_a_file`) REFERENCES `civicrm_file` (`id`) )]
    [type] => DB_Error
    [user_info] =>
INSERT INTO custom_value_11155_Test_Custom_Data_1 (domain_id,entity_id,Upload_a_file)
SELECT 11155, cv.entity_id, cv.char_data FROM civicrm_custom_value cv
WHERE cv.custom_field_id=5
ON DUPLICATE KEY UPDATE Upload_a_file=cv.char_data [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`sample_civicrm19fix/custom_value_11155_Test_Custom_Data_1`, CONSTRAINT `FK_custom_value_11155_Test_Custom_Data_1_Upload_a_file` FOREIGN KEY (`Upload_a_file`) REFERENCES `civicrm_file` (`id`) )]
    [to_string] => [db_error: message="DB Error: unknown error" code=-1 mode=callback callback=CRM_Core_Error::handle prefix="" info="
INSERT INTO custom_value_11155_Test_Custom_Data_1 (domain_id,entity_id,Upload_a_file)
SELECT 11155, cv.entity_id, cv.char_data FROM civicrm_custom_value cv
WHERE cv.custom_field_id=5
ON DUPLICATE KEY UPDATE Upload_a_file=cv.char_data [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`sample_civicrm19fix/custom_value_11155_Test_Custom_Data_1`, CONSTRAINT `FK_custom_value_11155_Test_Custom_Data_1_Upload_a_file` FOREIGN KEY (`Upload_a_file`) REFERENCES `civicrm_file` (`id`) )]"]
)

I've also got it in a slightly strange setup, but I don't THINK this is related.  In short I'm setup so that <drupal_root>/sites/sample/modules/civicrm/ is a link to a shared code base.  My reasoning behind this I'll discuss under the install section, since I want to test the theory that lead me to setup this way.

Aaron[/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: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 03, 2008, 01:19:02 pm

i think there is an issue with custom file fields in the upgrade process. Can you please send your db to deepak at webaccess.co.in and we'll sort it out before the next beta :)

thanx

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

rampkrm

  • Guest
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 04, 2008, 04:09:05 am
i am also hang up in step 5 if you find any solution let me also know.

acrosman

  • Guest
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 04, 2008, 07:35:00 am
I've sent a copy of the database before and after as requested.  We have several other databases, I could try them and see if/when those fail to update.  Would that be helpful at this stage, or would it be better to wait for the next beta?

Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 05, 2008, 04:50:22 am
Acrosman,

Thanks for the db.

The error you encountered was a bug related with custom field of type 'File', for which an issue has been filed and fixed - http://issues.civicrm.org/jira/browse/CRM-2805

The fix will be available with next beta release (expected in next 24 - 48 hrs), so better to wait for it (shouldn't be a problem for you, since i have mailed you the upgraded db).



Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

acrosman

  • Guest
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 05, 2008, 07:05:47 am
Waiting isn't a problem at all.  We were mostly doing the updates to see if they would work, and to make sure problems got filed/fixed before the final release.

Thanks for doing that, I look forward to trying the next beta.

Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 05, 2008, 07:42:35 am
Thanks a lot for helping us make it better :)
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 06, 2008, 05:58:42 am
Ok, been caught on that one too.

Is the fix on the svn already (I read the post on the blog about the mixed up release and didn't svn update since about a week) and is it "safe" to update ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 06, 2008, 07:42:51 am
Hi,

And to answer my own question: I put back the 1.9 db, svn updated, ran the update again and this time it rolled nicely.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

acrosman

  • Guest
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 06, 2008, 09:00:13 am
Still no joy here.  I now get to step 6 though, so that's progress.  Oddly these errors seem to be indicating that it can't create tables now, but I'm using a user with all access rights to the server (not just the database even).

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

    [code] => -15
    [message] => DB Error: can not create
    [mode] => 16
    [debug_info] => -- *
-- *
ALTER TABLE `civicrm_contribution`
    ADD `honor_type_id` int(10) unsigned NULL DEFAULT NULL COMMENT 'Implicit FK to civicrm_option_value.' AFTER contribution_status_id,
    DROP FOREIGN KEY `FK_civicrm_contribution_contact_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_page_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_recur_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_type_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_domain_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_honor_contact_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_solicitor_id` [nativecode=1005 ** Can't create table './sample_civicrm19fix/#sql-59e6_1324d.frm' (errno: 150)]
    [type] => DB_Error
    [user_info] => -- *
-- *
ALTER TABLE `civicrm_contribution`
    ADD `honor_type_id` int(10) unsigned NULL DEFAULT NULL COMMENT 'Implicit FK to civicrm_option_value.' AFTER contribution_status_id,
    DROP FOREIGN KEY `FK_civicrm_contribution_contact_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_page_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_recur_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_type_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_domain_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_honor_contact_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_solicitor_id` [nativecode=1005 ** Can't create table './sample_civicrm19fix/#sql-59e6_1324d.frm' (errno: 150)]
    [to_string] => [db_error: message="DB Error: can not create" code=-15 mode=callback callback=CRM_Core_Error::handle prefix="" info="-- *
-- *
ALTER TABLE `civicrm_contribution`
    ADD `honor_type_id` int(10) unsigned NULL DEFAULT NULL COMMENT 'Implicit FK to civicrm_option_value.' AFTER contribution_status_id,
    DROP FOREIGN KEY `FK_civicrm_contribution_contact_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_page_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_recur_id`,
    DROP FOREIGN KEY `FK_civicrm_contribution_contribution_type_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_domain_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_honor_contact_id` ,
    DROP FOREIGN KEY `FK_civicrm_contribution_solicitor_id` [nativecode=1005 ** Can't create table './sample_civicrm19fix/#sql-59e6_1324d.frm' (errno: 150)]"]
)

I'm happy to resend the databases if that would be helpful.[/code]

Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id
March 06, 2008, 09:16:07 am
I suspect this being a schema related issue.

Can you try making schema inline with 1.9 db (section 4, http://wiki.civicrm.org/confluence/display/CRMDOC/Upgrade+Drupal+Sites+to+2.0) ?

And then start with the upgrade and check if the same problem appears.
« Last Edit: March 06, 2008, 09:18:16 am by Deepak Srivastava »
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Error upgrading 1.9 to 2.0 -> foreign key constr. fails on activity_type_id

This forum was archived on 2017-11-26.