我有这样一个简单的实体:
<?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;
}
}
当我生成一个"diff"迁移时,doctrine自动创建一个查询,为列"activity_id"添加一个MariaDB INDEX。
在我的例子中,这个索引没有用,我希望将其删除,而不仅仅是将其从迁移中删除。
是否有办法指定不创建此索引?
谢谢你,
1条答案
按热度按时间n1bvdmb61#
删除类名定义上方的属性
#[ORM\Index(...)]
。尽管您要将该属性包括到实体的ID中,但可能会在列上创建索引。