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) »
  • DB error on 4.5.alpha1 upgrade
Pages: [1]

Author Topic: DB error on 4.5.alpha1 upgrade  (Read 609 times)

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
DB error on 4.5.alpha1 upgrade
June 24, 2014, 05:55:45 am
During the 'Upgrade DB to 4.5.alpha1: SQL' step, I get the following error ...

Quote
UPDATE civicrm_line_item SET contribution_id = entity_id WHERE contribution_id IS NULL and entity_table = 'civicrm_contribution' [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`cbf_civicrm_442`.`civicrm_line_item`, CONSTRAINT `FK_civicrm_contribution_id` FOREIGN KEY (`contribution_id`) REFERENCES `civicrm_contribution` (`id`) ON DELETE SET NULL)]

It appears the contribution_id field is being set to the id of a contribution that doesn't exist, and the FK constraint doesn't like that. See CRM-14197.

On my database, running ...

Code: [Select]
select
  li.*
from
  civicrm_line_item li
where
  li.contribution_id IS NULL
  and li.entity_table = 'civicrm_contribution'
  and not exists (select * from civicrm_contribution c where c.id = li.entity_id)

... yields 60 line-items where the contribution doesn't exist.

As the foreign key constraint that has been added to the line-item table is "ON DELETE SET NULL", I gather that the code copes with a NULL contribution_id, so I think it's safe to change the upgrade script (line 553 of CRM/Upgrade/Incremental/sql/4.5.alpha1.mysql.tpl) to ...

Code: [Select]
-- update line items for contributions with contribution id
UPDATE civicrm_line_item li
SET li.contribution_id = li.entity_id
WHERE li.contribution_id IS NULL and li.entity_table = 'civicrm_contribution'
and EXISTS (SELECT * FROM civicrm_contribution c WHERE c.id = li.entity_id);

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: DB error on 4.5.alpha1 upgrade
June 24, 2014, 01:45:21 pm
Hi Ken,
Thanks for your help on this. Could you check on your db how many rows are returned for the following query with the extra where clause in the subquery:

Code: [Select]
select
  li.*
from
  civicrm_line_item li
where
  li.contribution_id IS NULL
  and li.entity_table = 'civicrm_contribution'
  and not exists (select * from civicrm_contribution c where c.id = li.entity_id AND li.entity_table='civicrm_contribution')

Also, if you could post the result over to https://issues.civicrm.org/jira/browse/CRM-14197 that would be great. Thanks!
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: DB error on 4.5.alpha1 upgrade
June 24, 2014, 03:40:10 pm
Joe,

The answer is still 60. The extra condition just repeats a condition already in the where clause so it has no effect.

Could you explain what you're looking for in English and then I can play and have a look at my data?

Ken

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: DB error on 4.5.alpha1 upgrade
June 24, 2014, 05:54:59 pm
Duh. Thanks. You're absolutely correct, I wasn't looking closely/properly.
Thanks for the detaiks over in JIRA - we'll examine them tomorrow. It is useful to know the transactions date to 3.x. And I now recall that the table existed with a slightly different purpose prior to / in the first partial release of civiaccounts code; I may also be wrong i supposing civicrm_participant is the entity_table for participants.
Cheers, and thanks again for your help on this.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • DB error on 4.5.alpha1 upgrade

This forum was archived on 2017-11-26.