Search code examples
symfonydoctrine-orm

Single-Column Indexing in Symfony 6


There is a field:

#[ORM\Column(length: 255, nullable: true, )]
private ?string $inn = null;

How to add single-column indexing through migrations to avoid errors in Symfony.

I tried to find documentation about this on the official doctrine website, but found only info about relations indexes between entities.


Solution

  • At the top of the class, add something like this

    #[ORM\Index(columns: ['inn'], name: 'application_inn_idx')]
    

    Then generate a migration

    symfony console make:migration
    

    And then run the migration

    symfony console doctrine:migration:migrate