Can’t delete an entities which have related entries in a junction table in Symfony / Doctrine

I have the following entities:

Profile
Tag
TagCategpory
ProfileTag

ProfileTag is a junction table which forms a mahy to many relationship between Profile and Tag. Each Tag belobgs to a catepory.

I am having trouble removing all tag entries for a given profile, the fopllowing error is being produced when I do:

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 (app.profile_tag, CONSTRAINT
FK_AD2B1EBCBAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id))

Below are my entities:

<?php

#[ORMEntity(repositoryClass: ProfileRepository::class)]
#[ORMTable(name: '`profile`')]
class Profile
{
    #[ORMId]
    #[ORMGeneratedValue]
    #[ORMColumn]
    private ?int $id = null;

    #[ORMOneToMany(targetEntity: ProfileTag::class, mappedBy: 'profile', cascade: ['persist'])]
    private Collection $tag;


    public function getTag(): Collection
    {
        $tags = new ArrayCollection();
        foreach ($this->tag as $profileTag) {
            $tags->add($profileTag->getTag());
        }
        return $tags;
    }

    public function getTagByCategory(string $name): Collection
    {
        $tags = new ArrayCollection();
        foreach ($this->tag as $profileTag) {
            if ($profileTag->getTag()->getTagCategory()->getName() === $name) {
                $tags->add($profileTag->getTag());
            }
        }
        return $tags;
    }
}
?>

And Tag:

<?php

namespace AppEntity;

#[ORMEntity(repositoryClass: TagRepository::class)]
#[ORMTable(name: '`tag`')]
class Tag
{
    #[ORMId]
    #[ORMGeneratedValue]
    #[ORMColumn]
    private ?int $id = null;

    #[ORMColumn(type: 'string', length: 32, unique: false)]
    private ?string $name = '';

    #[ORMManyToOne(targetEntity: TagCategory::class, inversedBy: 'Tag')]
    #[ORMJoinColumn(nullable: false)]
    private ?TagCategory $tagCategory = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getTagCategory(): ?TagCategory
    {
        return $this->tagCategory;
    }

    public function setTagCategory(?TagCategory $tagCategory): self
    {
        $this->tagCategory = $tagCategory;
        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(?string $name): self
    {
        $this->name = $name;
        return $this;
    }
}
?>

And Tag Category:

<?php

namespace AppEntity;

use AppRepositoryTagCategoryRepository;
use DoctrineCommonCollectionsCollection;
use DoctrineORMMapping as ORM;

#[ORMEntity(repositoryClass: TagCategoryRepository::class)]
#[ORMTable(name: '`tag_category`')]
class TagCategory
{
    #[ORMId]
    #[ORMGeneratedValue]
    #[ORMColumn]
    private ?int $id = null;

    #[ORMColumn(type: 'string', length: 16, unique: false)]
    private ?string $name = '';

    #[ORMColumn(type: 'string', length: 32, unique: false)]
    private ?string $label = '';

    #[ORMOneToMany(targetEntity: Tag::class, mappedBy: 'tagCategory', cascade: ['persist'])]
    private ?Collection $tag = null;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): static
    {
        $this->name = $name;
        return $this;
    }

    public function getLabel(): ?string
    {
        return $this->label;
    }

    public function setLabel(string $label): static
    {
        $this->label = $label;
        return $this;
    }

    public function getTag(): ?Collection
    {
        return $this->tag;
    }

    public function setTag(Collection $tag): static
    {
        $this->tag = $tag;
        return $this;
    }
}
?>

And Finally ProfileTag, the junction table:

<?php

namespace AppEntity;

use AppRepositoryProfileTagRepository;
use DoctrineORMMapping as ORM;

#[ORMEntity(repositoryClass: ProfileTagRepository::class)]
#[ORMTable(name: '`profile_tag`')]
class ProfileTag
{
    #[ORMId]
    #[ORMManyToOne(targetEntity: Profile::class, inversedBy: 'profileTag')]
    #[ORMJoinColumn(nullable: false)]
    private ?Profile $profile = null;

    #[ORMId]
    #[ORMManyToOne(targetEntity: Tag::class, inversedBy: 'profileTag')]
    #[ORMJoinColumn(nullable: false)]
    private ?Tag $tag = null;

    public function getProfile(): ?Profile
    {
        return $this->profile;
    }

    public function setProfile(?Profile $profile): self
    {
        $this->profile = $profile;
        return $this;
    }

    public function getTag(): ?Tag
    {
        return $this->tag;
    }

    public function setTag(?Tag $tag): self
    {
        $this->tag = $tag;
        return $this;
    }
}
?>

And I attempt to remove in my controller as follows:

<?php

        $tags = $profile->getTag();
        foreach ($tags as $tag) {
            $this->entityManager->remove($tag);
        }
        $this->entityManager->flush();

?>

How can I remove tag safely, including it’s entry in the junction table?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật