我正在学习如何使用Symfony2和FOSUserBundle进行注册。我使用中提供的文档一步一步地进行此操作:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md但当我尝试运行命令php app/console doctrine:schema:update --force
时,我会收到以下错误:
[Doctrine'ORM'Mapping'MappingException]
No identifier/primary key specified for Entity "Registration'BusinessBundle'Entity'BusinessUser"
sub class of "FOS'UserBundle'Model'User".
Every Entity must have an identifier/primary key.
如果我运行命令php app/console cache:clear
,我会得到同样的错误。我尝试手动删除缓存文件夹,但当我尝试更新原则架构时,同样的错误再次出现。
我的业务用户实体:
<?php
namespace Registration'BusinessBundle'Entity;
use FOS'UserBundle'Model'User as BaseUser;
use Doctrine'ORM'Mapping as ORM;
/**
* @ORM'Entity
* @ORM'Table(name="business_user")
*/
class BusinessUser extends BaseUser
{
/*
* @ORM'Column(type="integer")
* @ORM'Id
* @ORM'GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
}
}
由于你在stackerflow中提出了两次这个问题,我复制并粘贴了我的答案:
您的实体不包含使用Doctrine Annotation的PHP文档块注释。
文档块是带有两个星号的startet,否则它只是一个简单的注释。
更改当前代码
/*
* @ORM'Id
* @ORM'Column(type="integer")
* @ORM'GeneratedValue(strategy="AUTO")
*/
protected $id;
至
/**
* @ORM'Id
* @ORM'Column(type="integer")
* @ORM'GeneratedValue(strategy="AUTO")
*/
protected $id;
只有使用/**,注释才会得到条令的承认。
也要检查您的其他属性。