Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new user with FOSUserBundle fails

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?

like image 309
sprain Avatar asked Jan 11 '13 11:01

sprain


2 Answers

Fixed!

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

like image 53
sprain Avatar answered Nov 03 '22 10:11

sprain


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
like image 25
Роман Мутасов Avatar answered Nov 03 '22 10:11

Роман Мутасов