Home > front end >  How to specify to Doctrine NOT to create an index
How to specify to Doctrine NOT to create an index

Time:02-02

I have this simple entity for example:

<?php

namespace App\Entity\Creator;

use App\Repository\Creator\ActivityContactRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ActivityContactRepository::class)]
#[ORM\Index(columns: ['contact_id'])]
class ActivityContact
{
    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: Activity::class, cascade: ['persist'])]
    private Activity $activity;

    #[ORM\Id]
    #[ORM\Column(name: 'contact_id', type: 'integer')]
    private int $contactId;

    public function __construct(Activity $activity, int $contactId)
    {
        $this->activity = $activity;
        $this->contactId = $contactId;
    }

    public function getActivity(): Activity
    {
        return $this->activity;
    }

    public function setActivity(Activity $activity): void
    {
        $this->activity = $activity;
    }

    public function getContactId(): int
    {
        return $this->contactId;
    }
}

When I generate a "diff" migration, doctrine automatically creates a query to add a MariaDB INDEX for the column "activity_id".

In my case, this index is not useful and I would like to remove it, without just deleting it from the migration.

Is there a way to specify to not create this index?

Thanks,

CodePudding user response:

@TEOL I think the only option that you need is to add an SQL query regarding the drop index in the migration file manually. There is no option available in Doctrine.

CodePudding user response:

Remove attribute #[ORM\Index(...)] above the class name definition. Although you are including that property into an ID of the Entity, the index may be created over the column.

  • Related