问题描述
我正在尝试从命令行创建新用户并获得此错误:
Warning: array_search() expects parameter 2 to be array, null given in /vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Model/User.php line 368
尝试通过网络接口注册创建用户时,我会得到:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'salt' cannot be null
使用已经存在的用户作品登录.还更新配置文件并更改密码.仅创建新用户不起作用.
我在非常普通的设置中使用V 1.3.1,尚未找到任何解决方案.
有什么想法?
推荐答案
修复!
我在用户实体中有一个自定义构造方法.在那里,我忘了用parent::__construct();
打电话给父母的构造函数其他推荐答案
也许它可以帮助某人.您可以在使用bcrypt coder时看到此错误.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'salt' cannot be null
要解决此问题,只需添加用户类中的盐属性的映射覆盖(使其无效)
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 { ... }
或:不要忘记更新模式.如果作曲家更新后出现错误!
bin/console doctrine:schema:update --force
问题描述
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?
推荐答案
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