Symfony Doctrine 架构更新无法重新声明 class

Symfony Doctrine schema update cannot redeclare class

当我想使用 Doctrine 命令 "php app/console doctrine:schema:update --force".[=12= 创建 Mysql 表时,我正在尝试调试命令 window 中的错误 "Fatal error: Cannot redeclare class Acme\UserBundle\Entity\User in C:\wamp\www\Symfony\src\Acme\UserBundle\entity\User.php on line 15" ]

这是我的实体代码的顶部:

namespace Acme\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Acme\UserBundle\Entity\User
 *
 * @ORM\Table(name="acme_users")
 * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
 */
class User implements UserInterface, \Serializable
{    
 //...

为了查看我可以在哪里双重声明我的 "User" class,我已重命名为 "User_alias" 并清除了我的缓存(使用 "php app/console cache:clear" 命令) .命令 window 然后在 User.php 行 15 中给我错误 "The table with name 'basededonne.acme_users' already exists.'. However, I do not see this table in phpmyadmin. In addition, my browser gives me the error "FatalErrorException:编译错误:无法重新声明 class Acme\UserBundle\Entity\User_alias”(我没有错误我的浏览器使用 "User" class).

谁能给我一些其他的选择来探索解决这个问题?我想我目前缺少更大的图景。

在您的 User_alias.php 中您有 class User 定义。

当您尝试在此命令的预热部分清除缓存时,symfony 会根据您的项目文件生成一些缓存文件。因此,在访问 User.php 中的 class User 之后,它再次访问 User_alias.php 中的 class User 并抛出错误。

尝试在 User_alias.php 中重命名您的 class,一切都会正常。