FOS 用户bundle注册"类型为 \Entity\User 的实体缺少字段'id'的分配 ID



我已经安装了FOS user bundle来管理登录&注册功能,但是当我尝试注册一个新用户时,我收到以下错误:

    Entity of type ********EntityUser 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.

这是我的User.php类:

<?php
// src/Acme/UserBundle/Entity/User.php
namespace  ******Entity;
use FOSUserBundleModelUser as BaseUser;
use DoctrineORMMapping as ORM;
/**
 * @ORMEntity
 * @ORMTable(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     */
    protected $id;

这是我的User.orm.yml:

********EntityUser:
type:  entity
table: fos_user
fields:
    id:
        id:
            type: integer
            generator:
                strategy: AUTO

我知道在持久化新用户的数据时会出现问题,但是我不知道如何让Symfony生成这个id字段。谢谢!

您的yml应该看起来像

type:  entity
table: fos_user
id:
     id:
         type: integer
            generator:
                strategy: AUTO
fields: 

等等…

您的yml配置错误,请尝试:

type:  entity
table: fos_user
fields:
    id:
        id:
            type: integer
            generator:
                strategy: AUTO

我的问题解决了。这是我的User.php类:

<?php
namespace **********Entity;
use FOSUserBundleModelUser as BaseUser;
use DoctrineORMMapping as ORM;
/**
 * @ORMEntity
 * @ORMTable(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;

我刚刚删除了所有YAML配置文件,这是注解和YAML之间的冲突问题。现在注册和登录工作正常

最新更新