我在Symfony Bundle类中使用以下代码创建了一个带有Doctrine的Table:
<?php
namespace Acme\Bundle\TranslationMessagesProducerBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Entity
* @ORM\Table(name="acme_translation_config")
*
*/
class AcmeTranslationMessagesProducerEntity{
/**
* id - for doctrine
* @ORM\Column(type="integer")
* @ORM\Id()
* @var integer
*/
private $id;
/**
* enabled
* @ORM\Column(type="boolean")
* @var mixed
*/
private $enabled;
public function getId(){
return $this->id;
}
public function getEnabled(){
return $this->enabled;
}
}
并且此表在运行php bin/console doctrine:schema:update --force
后存在,我可以通过查询php bin/console doctrine:query:sql "Select * From acme_translation_config
来验证它是否存在,也可以运行:php bin/console doctrine:query:sql "Select * From akeneo_pim.acme_translation_config
Doctrine也认识到这一点,并通过运行以下命令进行验证:php bin/console doctrine:mapping:info
,结果为:
Found 58 mapped entities: ....
Acme\Bundle\TranslationMessagesProducerBundle\Entity\AcmeTranslationMessagesProducerEntity
然而,如果我尝试从这个表中获取一个对象,如下所示:
$em = $this->getDoctrine()->getManager();
$config = $em->getRepository(AcmeTranslationMessagesProducerEntity::class)->find(1);
我得到了失败:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'akeneo_pim.acme_translation_config' doesn't exist
怎么解决呢?
1条答案
按热度按时间col17t5w1#
替换此
通过以下方式:
并检查
AcmeTranslationMessagesProducerEntityRepository.php
是否存在PS:你应该遵守命名规则,不要在类名中添加“Entity”:
AcmeTranslationMessagesProducer
优于AcmeTranslationMessagesProducerEntity