Skip to content

Migration error during update from 5.1 to 6.1 when some orders were removed #176

Description

@yaroslavbr

Summary
Here is such error appear during the update command from 5.1 to 6.1:

` 143.00 MiB - 141 ms

Oro\Bundle\CheckoutBundle\Migrations\Schema\v1_17\AddOrderToCheckout
ERROR: An exception occurred while executing 'UPDATE oro_checkout SET order_id = ((wi.data::jsonb->>'order')::jsonb->>'id')::integer FROM oro_workflow_item wi WHERE wi.entity_class = ? AND wi.entity_id::integer = oro_checkout.id' with params ["Oro\Bundle\CheckoutBundle\Entity\Checkout"]:

SQLSTATE[23503]: Foreign key violation: 7 ERROR: insert or update on table "oro_checkout" violates foreign key constraint "fk_oro_checkout_order_id"
DETAIL: Key (order_id)=(47) is not present in table "oro_order".`

Steps to reproduce
Execute update command from 5.1 to 6.1. Precondition: seems some orders should be removed before.

Actual Result
Error apepars described in the summary

Expected Result
Update should pass successfully

Solution
I modified commerce/src/Oro/Bundle/CheckoutBundle/Migrations/Schema/v1_17/AddOrderToCheckout.php

with such code:
$queries->addPostQuery( new ParametrizedSqlMigrationQuery( <<<SQL UPDATE oro_checkout SET order_id = ((wi.data::jsonb->>'order')::jsonb->>'id')::integer FROM oro_workflow_item wi JOIN oro_order o ON o.id = ((wi.data::jsonb->>'order')::jsonb->>'id')::integer WHERE wi.entity_class = :entityClass AND wi.entity_id::integer = oro_checkout.id SQL , ['entityClass' => Checkout::class], ['entityClass' => Types::TEXT] ) );

Details about your environment

  • OroCommerce version: 5.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions