Integrity constraint violation In api-platform

Viewed 21

I have a custom Many to Many relation table called location_media in order to add more fields to it. Two foreign keys are defined like this:

#[ORM\ManyToOne(targetEntity: Location::class, inversedBy: 'media', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Location $location = null;

#[ORM\ManyToOne(targetEntity: Media::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Media $media = null;

the problem is on removing a media resource , it is expected that related location_media is being deleted, but it returns the Integrity problem.

This is auto-generated migrations that create constraint

$this->addSql('ALTER TABLE location_media ADD CONSTRAINT FK_1C70E42964D218E FOREIGN KEY (location_id) REFERENCES location (id)');
$this->addSql('ALTER TABLE location_media ADD CONSTRAINT FK_1C70E429EA9FDD75 FOREIGN KEY (media_id) REFERENCES media (id)');

The answer to this problem is adding ON DELETE CASCADE to end of these two lines. The problem is that I want this auto-generated file create ON DELETE CASCADE at the end of it by itself and not forcing me to add those manually.

0 Answers
Related