Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantical Error - Couldn't find constant X, class... ERROR

I am trying to implement category and subcategory structure entity, but I end up with this error when generating entity with command php app/console generate:doctrine:entities RFQIronilBundle:

  [Doctrine\Common\Annotations\AnnotationException]                            
  [Semantical Error] Couldn't find constant production, class RFQ\IronilBundl  
  e\Entity\ProductionType.

My created ProductionType entity:

<?php

namespace RFQ\IronilBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * ProductionType
 *
 * @ORM\Table(production-type)
 * @ORM\Entity
 */
class ProductionType
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=100)
     */
    protected $name;

    /**
     * @ORM\OneToMany(targetEntity="ProductionType", mappedBy="parent")
     **/
    protected $children;

    /**
     * @ORM\ManyToOne(targetEntity="ProductionType", inversedBy="children")
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
     **/
    protected $parent;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
}

How to generate my entity and what could causes this error? Thank you!

like image 805
RydelHouse Avatar asked Feb 13 '23 10:02

RydelHouse


1 Answers

I think it's because you aren't using speech marks around your table name.

@ORM\Table(production-type) // meant (constant) production minus (constant) type

where as you should use

@ORM\Table("production-type")

And it may make more sense to use production_type to stop the need to quotation marks around the table name in MySQL statements.

like image 79
qooplmao Avatar answered Feb 15 '23 10:02

qooplmao