简体   繁体   English

使用Symfony2和Doctrine更新数据库中的索引

[英]Updating indexes in database with Symfony2 and Doctrine

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. 我正在尝试使用用户实体类中的注释方法将索引添加到数据库中,但是,当我更新元数据并从命令行运行更新然后转到phpMyAdmin时,相关表没有索引。 I have a users table with a role_id foreign key and want to add this as an index using the meta data below: 我有一个带role_id外键的用户表,并希望使用以下元数据将其添加为索引:

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? 我假设columns =是我要索引的字段名称?

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 参见《 Doctrine 2文档》

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM