简体   繁体   中英

Symfony2 FOSUserBundle change fos_user id type

I have problem. I have to change type of fos_user.id to bigint. But I don't know how to do it. I have overriden the FOSUserBundle and I have tried code below, it's works but not for id.:

/**
 * @ORM\Entity
 * @ORM\Table(name="sf_guard_user")
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="id", column=@ORM\Column(type="bigint", name="id")),
 *      @ORM\AttributeOverride(name="email", column=@ORM\Column(type="string", name="email_address", length=255)),
 * })
 */
class User extends BaseUser implements EncoderAwareInterface {
 //...
}

You don't need to override id . It should be defined in class that extends FOS\\UserBundle\\Model\\User . Just define it inside your User class. Like this:

/**
 * @ORM\Entity
 * @ORM\Table(name="sf_guard_user")
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="email", column=@ORM\Column(type="string", name="email_address", length=255)),
 * })
 */
class User extends BaseUser implements EncoderAwareInterface {
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

 //...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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