I have some issue deleting a foreign key from a self-referencing entity. I would like to remove an entity and delete its reference (feature_group_parent_id) from any other entities.
/**
* @Entity
* @Table(name="ps_biotexconfigurator_feature_groups")
*/
class ConfFeatureGroup
{
/**
* @var string
*
* @Id
* @Column(type="string")
* @GeneratedValue(strategy="NONE")
*/
private $id_biotexconfigurator_feature_group;
/**
* @var int
*
* @Column(type="integer")
*/
private $feature_id;
/**
* @var string
*
* @Column(type="string", nullable=true)
*/
private $feature_group_parent_id;
/**
* @var ConfFeatureGroup
*
* @OneToOne(targetEntity="BiotexConfigurator\Entity\ConfFeatureGroup")
* @JoinColumn(name="feature_group_parent_id", referencedColumnName="id_biotexconfigurator_feature_group", onDelete="SET NULL")
*/
private $feature_group_parent;
// Other fields ...
}
I am using the version included in Prestashop 1.7.8, which should be v2.6.
As you can see, I have already tried with onDelete="SET NULL" but it does not work, here is the error message:
Uncaught PHP Exception Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException: "An exception occurred while executing 'DELETE FROM ps_biotexconfigurator_feature_groups WHERE id_biotexconfigurator_feature_group = ?' with params ["234b3aba-36ee-4ff8-a497-ad54beceb86d"]: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`prestashop`.`ps_biotexconfigurator_feature_groups`, CONSTRAINT `ps_biotexconfigurator_feature_groups_ibfk_1` FOREIGN KEY (`feature_group_parent_id`) REFERENCES `ps_biotexconfigurator_feature_)" at /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 49
Is there a way to do it without writing a raw query before?