所以,看起来 就像生成器正在加载 CreditNote.php ,找到扩展 Invoice 的类,然后加载Invoice.php ,然后再次找到 Invoice.php 文件,并尝试对其进行第二次解析.到现在为止,这似乎只是某人已经解决的那种事情.有什么想法吗?谢谢.解决方案它是100%正常工作的代码-我刚刚尝试过您可能只需要使用以下方法清理缓存: php应用程序/控制台缓存:清除&&php应用程序/控制台缓存:clear --env = prod 但是我使用php app/console doctrine:schema:update(不是doctrine:database:create)An interesting problem. I'm building an application using Symfony 2 and I'm trying to get Doctrine to auto-generate my schema from my entity classes. I have two entity classes, Invoice and CreditNote. CreditNote extends Invoice. They look like this -Invoice.php - namespace My\Bundle\BillingBundle\Entity;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity * @ORM\Table(name="invoice") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="discriminator", type="string") * @ORM\DiscriminatorMap({"invoice" = "Invoice", "credit_note" = "CreditNote"}) */class Invoice{ ... }and CreditNote.php - namespace My\Bundle\BillingBundle\Entity;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity */class CreditNote extends Invoice{ ... }...all of which seems to follow Doctrine's guidance on single table inheritance at http://docs.doctrine-project.org/en/2.0.x/reference/inheritance-mapping.html#single-table-inheritance.But, when I try to run php app/console doctrine:database:create in order to generate my schema I get the error - PHP Fatal error: Cannot redeclare class My\Bundle\BillingBundle\Entity\Invoice in <my-app>/src/My/Bundle/BillingBundle/Entity/Invoice.php on line 15Which suggests that the Invoice class has already been declared (but it honestly hasn't). More interesting is that if I rename the Invoice class to AInvoice (i.e. something that comes before CreditNote in the alphabet, then everything works.So, it seems like the generator is loading up CreditNote.php, finding a class that extends Invoice and then loading Invoice.php, then finding the Invoice.php file again and trying to parse it a second time. Only that seems the kind of thing that someone would have fixed by now.Any thoughts? Thanks. 解决方案 it is 100% working code - I tried justYou may need just to clean the cache using:php app/console cache:clear && php app/console cache:clear --env=prodbut I use php app/console doctrine:schema:update (not doctrine:database:create) 这篇关于使用单表继承时,Doctrine无法生成模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!