Creating a new user with FOSUserBundle fails

2019-03-10 13:31发布

I am trying to create a new user from the command line and get this error:

Warning: array_search() expects parameter 2 to be array, null given
in /vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Model/User.php line 368  

When trying to create a user by registering over the webinterface I get this:

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

Logging in with an already existing user works. Also updating a profile and changing the password. Just creating new users doesn't work.

I am using v 1.3.1 in a very plain setup and haven't found any solution yet.

Any ideas?

2条回答
孤傲高冷的网名
2楼-- · 2019-03-10 13:51

Fixed!

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

查看更多
聊天终结者
3楼-- · 2019-03-10 14:06

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
查看更多
登录 后发表回答