我正试图在现有数据库的基础上添加Doctrine。我让Doctrine生成带注释的实体,并从那里进行调整。当我尝试加载下面的实体时,我得到错误PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Property Users''User::$resellerID does not exist'
class User
{
/* ... */
/**
* @var 'Doctrine'Common'Collections'Collection
*
* @ORM'ManyToOne(targetEntity="'Resellers'Reseller")
* @ORM'JoinTable(name="reseller",
* joinColumns={
* @ORM'JoinColumn(name="resellerID", referencedColumnName="resellerID")
* },
* inverseJoinColumns={
* @ORM'JoinColumn(name="resellerID", referencedColumnName="resellerID")
* }
* )
*/
private $reseller;
/* ... */
}
user
和reseller
表都具有resellerID
列。我的理解是,对于联接ID列,您不会将ID列作为属性添加到实体类中。那么是什么导致了ReflectionException?
由于我已经将自动生成的属性从resellerID
重命名为reseller
(在尝试使用它之后),因此我需要清除Doctrine缓存。
php vendor/bin/doctrine.php orm:clear-cache:result
php vendor/bin/doctrine.php orm:clear-cache:query
php vendor/bin/doctrine.php orm:clear-cache:metadata
或者,如果你正在使用Symfony with Doctrine:
php bin/console doctrine:cache:clear-result
php bin/console doctrine:cache:clear-query
php bin/console doctrine:cache:clear-metadata
对我来说,清除PHP APC缓存是的解决方案
<?php
apc_clear_cache();
不管怎样,它帮助了我
php artisan doctrine:clear:metadata:cache
通常在生产中,您想要这样的东西:
php bin/console doctrine:cache:clear-result --env=prod
php bin/console doctrine:cache:clear-query --env=prod
php bin/console doctrine:cache:clear-metadata --env=prod
当我试图清除条令缓存时,仍然发生了错误。
对我来说有效的是通过删除/storage/framework/cache/*
下的文件夹来手动清除缓存
在Symfony中,由于Docker容器权限的原因,我不得不手动删除/var/cache/下的所有内容。
如果有人在使用Docker容器时阅读了这篇文章:
- 在PHP/Symfony容器中使用终端
- 输入旧答案中引用的条令缓存清除命令:
php bin/console doctrine:cache:clear-result
php bin/console doctrine:cache:clear-query
php bin/console doctrine:cache:clear-metadata
- 是否清除旧答案中也提到的APC缓存:
php -r "apc_clear_cache();"
- 在Docker中重新启动PHP/Symfony容器
作为最后一步的重启最终会清除任何挥之不去的东西,至少在我的情况下是这样。希望这能帮助到其他使用Docker的人。