Orphan removal is executed after resultingIntegrity constraint violation when re-adding a new item with the same code #6503

Closed
opened 2026-01-22 15:34:11 +01:00 by admin · 1 comment
Owner

Originally created by @mynameisbogdan on GitHub (Jul 12, 2020).

Bug Report

Q A
Version 2.7.3

Summary

When removing an item with a unique code index from a OneToMany relationship and re-adding a new item with the some code it will result into a SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed

Current behavior

How to reproduce

git clone https://github.com/mynameisbogdan/doctrine-orphan-removal-bug
composer install
bin/console doctrine:migrations:migrate 20200712125057 -n
bin/console doctrine:fixtures:load -n
bin/console app:doctrine-orphan-removal # gives SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed

bin/console doctrine:migrations:migrate 20200712125117 -n # to drop the unique index
bin/console app:doctrine-orphan-removal # sql logger shows the insert(s) are before the delete queries

Screenshot 2020-07-12 at 16 01 29

Expected behavior

In this case maybe orphan removal should be executed first and then insert the new data.

Originally created by @mynameisbogdan on GitHub (Jul 12, 2020). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | Version | 2.7.3 #### Summary When removing an item with a unique code index from a OneToMany relationship and re-adding a new item with the some code it will result into a `SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed` #### Current behavior <!-- What is the current (buggy) behavior? --> #### How to reproduce ```sh git clone https://github.com/mynameisbogdan/doctrine-orphan-removal-bug composer install bin/console doctrine:migrations:migrate 20200712125057 -n bin/console doctrine:fixtures:load -n bin/console app:doctrine-orphan-removal # gives SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed bin/console doctrine:migrations:migrate 20200712125117 -n # to drop the unique index bin/console app:doctrine-orphan-removal # sql logger shows the insert(s) are before the delete queries ``` ![Screenshot 2020-07-12 at 16 01 29](https://user-images.githubusercontent.com/707714/87246943-5ecf5180-c459-11ea-9803-10e0bc3cea08.jpg) #### Expected behavior In this case maybe orphan removal should be executed first and then insert the new data.
admin closed this issue 2026-01-22 15:34:12 +01:00
Author
Owner

@nescim commented on GitHub (Nov 25, 2020):

I had a similar, probably related, issue where the FK column in the related entity is not nullable.

Attempts to rely on orphan removal result in an error because the FK column is being set to NULL rather than the row being DELETEd altogether.

@nescim commented on GitHub (Nov 25, 2020): I had a similar, probably related, issue where the FK column in the related entity is not nullable. Attempts to rely on orphan removal result in an error because the FK column is being set to `NULL` rather than the row being `DELETE`d altogether.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6503