Creating a new user with FOSUserBundle fails

◇◆丶佛笑我妖孽 提交于 2019-12-02 19:58:34

Fixed!

I had a custom constructor method in my User entity. There I had forgotten to call the parent's constructor with parent::__construct();

Maybe it help someone. You can see this error when use bcrypt encoder.

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'salt' cannot be null

To solve this issue just add mapping override for salt attribute in your User class (make it nullable)

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\AttributeOverrides({
 *  @ORM\AttributeOverride(
 *      name="salt",
 *      column=@ORM\Column(name="salt", type="string", nullable=true)
 *      )
 *  })
 */
class User extends BaseUser {
     ...
}

OR: don't forget update your schema. If error happend after composer update!

bin/console doctrine:schema:update --force
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!