[英]FOS user bundle Registration "Entity of type \Entity\User is missing an assigned ID for field 'id'
I've installed FOS user bundle
to manage login & registration features, but when I try to register a new user I receive the following error: 我已经安装了
FOS user bundle
来管理登录和注册功能,但是当我尝试注册新用户时,出现以下错误:
Entity of type ****\****\Entity\User is missing an assigned ID for field 'id'.
The identifier generation strategy for this entity requires the ID field to be
populated before EntityManager#persist() is called. If you want automatically
generated identifiers instead you need to adjust the metadata mapping accordingly.
This is my User.php class: 这是我的User.php类:
<?php
// src/Acme/UserBundle/Entity/User.php
namespace ***\***\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
protected $id;
and this is my User.orm.yml: 这是我的User.orm.yml:
****\****\Entity\User:
type: entity
table: fos_user
fields:
id:
id:
type: integer
generator:
strategy: AUTO
I know that the problem appears when persisting the data of a new user, but I don't know how to make Symfony
generate this id
field. 我知道在保留新用户的数据时会出现问题,但是我不知道如何使
Symfony
生成此id
字段。 Thanks! 谢谢!
Your yml
configuration is wrong, try with: 您的
yml
配置错误,请尝试:
type: entity
table: fos_user
fields:
id:
id:
type: integer
generator:
strategy: AUTO
I've solved my problem. 我已经解决了我的问题。 This is my User.php Class:
这是我的User.php类:
<?php
namespace *****\*****\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
And I've just deleted ALL YAML
configurations files, it was a conflict problem between Annotations and YAML
. 而且我刚刚删除了所有
YAML
配置文件,这是Annotations和YAML
之间的冲突问题。 Now registration and login work fine. 现在注册和登录工作正常。
Your yml should looks like 您的yml应该看起来像
type: entity
table: fos_user
id:
id:
type: integer
generator:
strategy: AUTO
fields:
etc... 等等...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.