Skip to content

[5.x]: C4 -> C5 post upgrade, adding new matrix blocks gives FK error on first click, works on 2nd click #18560

@chadcrowell

Description

@chadcrowell

What happened?

Description

On C4 -> C5 upgraded site when trying to add matrix blocks to existing entries that had existing matrix (or possibly super table) blocks before the upgrade, getting a FK constraint error. Second click to add the block successfully adds it and can add content and save. So, only on first click.

Video with demonstration of what is happening

Initial Chat GPT Chat

Claude Chat

I decided not to get into doing a composer patch to see if there's a fix for this or if I am overlooking something somewhere. So, pausing for now to see what the response is.

Steps to reproduce

  1. See video above

Expected behavior

No FK error to be shown

Actual behavior

FK errors:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (db.craft_elements_owners, CONSTRAINT craft_fk_qbhiiwsnvxpysusastgppytrauyrjehnikns FOREIGN KEY (elementId) REFERENCES craft_elements (id) ON DELETE CASCADE) The SQL being executed was: INSERT INTO craft_elements_owners (elementId, ownerId, sortOrder) SELECT o.elementId, 7090464, o.sortOrder FROM craft_elements_owners AS o WHERE o.ownerId = 6

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (db.craft_elements_owners, CONSTRAINT craft_fk_qbhiiwsnvxpysusastgppytrauyrjehnikns FOREIGN KEY (elementId) REFERENCES craft_elements (id) ON DELETE CASCADE) The SQL being executed was: INSERT INTO craft_elements_owners (elementId, ownerId, sortOrder) SELECT o.elementId, 7090467, o.sortOrder FROM craft_elements_owners AS o WHERE o.ownerId = 486111

Craft CMS version

5.19.6

PHP version

8.2.30 and 8.4.18 (ddev) and 8.2.28 (servd)

Operating system and version

MacOS recent

Database type and version

MySql 8.0 ddev and Servd

Image driver and version

Imagick 3.8.1 (ImageMagick 7.1.1-43) and Imagick 3.7.0 (ImageMagick 7.1.1-41)

Installed plugins and versions

Plugins

Asset Rev 8.0.0
Child Me! 2.2.3
CKEditor 4.11.2
Control Panel Nav 5.0.6
Environment Label 5.0.0
Feed Me 6.11.0
Icon Picker 3.0.7
Publisher X 5.0.3
Retour 5.0.14
SEOmatic 5.1.20
Servd Assets and Helpers 4.2.3
Wordsmith 5.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions