Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-11415

4.3 Upgrade fails with foreign key constraint due to required financial_type_id column being added for tables that have rows

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Critical
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.3.0
    • Fix Version/s: 4.3.0
    • Component/s: Accounting Integration
    • Labels:

      Description

      Currently we are trying to add financial_type_id column NOT NULL to civicrm_payment_processor table with FK to civicrm_financial_type.id. If the DB being upgraded has one or more existing rows in civicrm_payment_processor table - you will get this FATAL error:

      ALTER TABLE `civicrm_payment_processor` ADD CONSTRAINT `FK_civicrm_payment_processor_financial_type_id` FOREIGN KEY (`financial_type_id`) REFERENCES `civicrm_financial_type` (`id`) [nativecode=1452 ** Cannot add or update a child row: a foreign key constraint fails (`civicrm_42`., CONSTRAINT `FK_civicrm_payment_processor_financial_type_id` FOREIGN KEY (`financial_type_id`) REFERENCES `civicrm_financial_typ)]
      DebugInfo

      The upgrade script needs to insert reasonable defaults for financial types to be used in payment_processor table as well as the other tables where financial_type_is column is being added. Then all can be set to NOT NULL via a second ALTER TABLE command.

      I've temporarily fixed this by changing column definition for civicrm_payment_processor.financial_type_id to DEFAULT NULL.

        Attachments

          Activity

            People

            • Assignee:
              joemurray Joe Murray
              Reporter:
              dgg David Greenberg
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: