How can I add an INDEX with Doctrine 2 to a column without making it a primary key?

If you want to work with doctrine a table must have a primary key, see:

Every entity class must have an identifier/primary key. You can select the field that serves as the identifier with the @Id annotation.

Reference: Identifiers and Primary keys

To create an index: Annotations Reference

<?php
/**
 * @Entity
 * @Table(name="ecommerce_products",indexes={
 *     @Index(name="search_idx", columns={"name", "email"})
 * })
 */
class ECommerceProduct
{
}

Note that this is only being used if you generate the schema from your PHP code. So in case your table already exist you can also just add an index yourself.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)