I’m trying to add indexes to my database using the annotation method in my User Entity class, however when I update the meta data and run an update from the command line and then go to phpMyAdmin there are no indexes for the relevant table. I have a users table with a role_id foreign key and want to add this as an index using the meta data below:
namespace XXX\XXXBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @Table(name="user",indexes={@index(name="role_id", columns={"role_id"})})
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class User {
}
Also, can someone please explain what the Index name refers to? Can this be set to anything? I assume the columns= is the field names I want to index?
Your Index-Annotion is just on the wrong place. It has to be a annotion of the class and not of a property.
See Doctrine 2 Docs