'ManyToOne OnDelete set Null triggers foreign key constraint violation
The parent Entity assotiation field:
/**
* @ORM\OneToMany(targetEntity=AnswersAspects::class, mappedBy="Users")
*/
private $AnswersAspects;
And the child Entity assotiation field:
/**
* @ORM\ManyToOne(targetEntity=Users::class, inversedBy="AnswersAspects")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $Users;
I have the onDelete="SET NULL" on the Child, but when I try to remove the parent, I get the FK violation error:
An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails ('answers_notes', CONSTRAINT 'FK_71C7235F67B3B43D' FOREIGN KEY ('users_id') REFERENCES 'users' ('id'))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
