craftcms / craftcms/cms

[3.5.x-dev] Save Element form w/ uploaded file: Integrity constraint violation

Open
#6,396 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

I have a frontend entries/save-entry with a file input for an assets field.

Looks like some params aren't getting set in the query, causing a constraint violation.
Same form worked in 3.4.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (craftcms_local.relations, CONSTRAINT relations_targetId_fk FOREIGN KEY (targetId) REFERENCES elements (id) ON DELETE CASCADE)
The SQL being executed was: INSERT INTO relations (fieldId, sourceId, sourceSiteId, targetId, sortOrder, dateCreated, dateUpdated, uid) VALUES (258, 142919, NULL, 0, 1, '2020-07-16 12:52:40', '2020-07-16 12:52:40', 'abec2f08-b3d3-4f51-aa92-971240ebe0fd')

Additional info
  • Craft version: craftcms/cms 3.5.x-dev (6d6b8ae)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the frontend entries/save-entry submission with a file input for an assets field on the reported Craft 3.5.x-dev version. Inspect how the submitted parameters become the relations INSERT, especially the targetId value shown as 0. Done means the form saves successfully without the reported foreign-key constraint violation and remains compatible with the stated form behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.