Php SQLSTATE[42S22]:未找到列

Php SQLSTATE[42S22]:未找到列,php,symfony,doctrine-orm,doctrine,Php,Symfony,Doctrine Orm,Doctrine,我已创建Formtype UniversitaireType,但出现以下错误: 当我尝试命令php-bin/console-doctrine:schema:update--force时,attribute condidat_id不会在数据库中创建(除id_condidat外,所有属性都在数据库中创建)。。我在实体大学做了一个多美元的地图 代码实体: <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; u

我已创建Formtype UniversitaireType,但出现以下错误:

当我尝试命令php-bin/console-doctrine:schema:update--force时,attribute condidat_id不会在数据库中创建(除id_condidat外,所有属性都在数据库中创建)。。我在实体大学做了一个多美元的地图

代码实体:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\Condidat;

/**
 * Universitaire.
 *
 * @ORM\Table(name="universitaires")
 * @ORM\Entity(repositoryClass="AppBundle\Entity\UniversitaireEntityRepository")
 */
class Universitaire
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="date_start", type="string", length=255, nullable=true)
     */
    private $dateStart;

    /**
     * @var string
     *
     * @ORM\Column(name="date_end", type="string", length=255, nullable=true)
     */
    private $dateEnd;

    /**
     * @var string
     *
     * @ORM\Column(name="establishment", type="string", length=255, nullable=true, unique=true)
     */
    private $establishment;


    /**
     * @var string
     *
     * @ORM\Column(name="diploma", type="string", length=255, nullable=true, unique=true)
     */
    private $diploma;

    /**
     *@ORM\OneToMany(targetEntity="AppBundle\Entity\Condidat",mappedBy="id_universitaire",cascade={"persist"})
     *@ORM\JoinColumn(name="id_condidat", referencedColumnName="id")
     */
    private $condidat;

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

    /**
     * Add Condidat
     *
     * @param \AppBundle\Entity\Condidat $condidat
     * @return Universitaire
     */
    public function addCondidat(\AppBundle\Entity\Condidat $condidat)
    {
        $this->condidat[] = $condidat;

        return $this;
    }

    /**
     * Remove Condidat
     *
     * @param \AppBundle\Entity\Condidat $condidat
     */
    public function removeCondidat(\AppBundle\Entity\Condidat $condidat)
    {
        $this->Condidat->removeElement($condidat);
    }

    /**
     * Get Condidat
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getCondidat()
    {
        return $this->condidat;
    }


    /**
     * Set dateStart.
     *
     * @param string $dateStart
     *
     * @return Universitaire
     */
    public function setdateStart($dateStart)
    {
        $this->dateStart = $dateStart;

        return $this;
    }

    /**
     * Get dateStart.
     *
     * @return string
     */
    public function getdateStart()
    {
        return $this->dateStart;
    }

    /**
     * Set dateEnd.
     *
     * @param string $dateEnd
     *
     * @return Universitaire
     */
    public function setDateEnd($dateEnd)
    {
        $this->dateEnd = $dateEnd;

        return $this;
    }

    /**
     * Get dateEnd.
     *
     * @return string
     */
    public function getdateEnd()
    {
        return $this->dateEnd;
    }

    /**
     * Set establishment.
     *
     * @param string $establishment
     *
     * @return Universitaire
     */
    public function setEstablishment($establishment)
    {
        $this->establishment = $establishment;

        return $this;
    }

    /**
     * Get establishment.
     *
     * @return string
     */
    public function getEstablishment()
    {
        return $this->establishment;
    }

    /**
     * Set diploma.
     *
     * @param string $diploma
     *
     * @return Universitaire
     */
    public function setDiploma($diploma)
    {
        $this->diploma = $diploma;

        return $this;
    }

    /**
     * Get diploma.
     *
     * @return string
     */
    public function getDiploma()
    {
        return $this->diploma;
    }

    public function __construct()
    {
        $this->ResponsableCategory = new \Doctrine\Common\Collections\ArrayCollection();
    }

    }

您的“condidat”属性中有两个错误

  • 您使用了一对多(双向)。如果你只想要一个 每个“Universitaire”的候选人-然后你必须使用一对一(双向)

  • 如果不是,并且一对多正是您想要的,那么您必须在
    \uu construct()
    中设置“condidat”是一个数组集合

    public function __construct()
    {
        $this->condidat = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    如果我是你,我宁愿用“候选者”和“s”来表示这是一个数组集合

  • 正如我已经说过的,你的例子是双向的一对多。在本例中,我们使用mappedBy和inversedBy。实体,在其中设置联接列为所属方。当然,JoinColumn必须位于“候选”实体中。因此:

    class Universitaire
    {
    
        ## ...
    
        /**
         * Bidirectional One-To-Many (Owning Side)
         * Predicate: One Universitaire can have a lot of candidates
         * 
         * @ORM\OneToMany(
         *     targetEntity="AppBundle\Entity\Condidat",
         *     mappedBy="universitaire",
         *     cascade={"persist", "remove"}
         *     )
         */
         private $condidats;
    
    class Condidat
    {
    
        ## ...
    
        /**
         * Bidirectional Many-To-One (Owning Side)
         * Predicate: Each Condidat belongs to one Universitaire
         * 
         * @ORM\ManyToOne(
         *     targetEntity="AppBundle\Entity\Universitaire",
         *     inversedBy="condidats",
         *     )
         * @ORM\JoinColumn(
         *     name="universitaire_id",
         *     referencedColumnName="id", 
         *     onDelete="SET NULL"
         *      )
         */
         private $universitaire;
    

  • 我添加了
    onDelete=“SET NULL”
    。如果删除universitaire,则在每个“条件”的universitaire字段中,您将看到空值

    看起来,“f0_u.username”列不存在。检查数据库中表“f0_389;”的结构。AppBundle\entity\Condidat的Post实体定义
    public function __construct()
    {
        $this->condidat = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    class Universitaire
    {
    
        ## ...
    
        /**
         * Bidirectional One-To-Many (Owning Side)
         * Predicate: One Universitaire can have a lot of candidates
         * 
         * @ORM\OneToMany(
         *     targetEntity="AppBundle\Entity\Condidat",
         *     mappedBy="universitaire",
         *     cascade={"persist", "remove"}
         *     )
         */
         private $condidats;
    
    class Condidat
    {
    
        ## ...
    
        /**
         * Bidirectional Many-To-One (Owning Side)
         * Predicate: Each Condidat belongs to one Universitaire
         * 
         * @ORM\ManyToOne(
         *     targetEntity="AppBundle\Entity\Universitaire",
         *     inversedBy="condidats",
         *     )
         * @ORM\JoinColumn(
         *     name="universitaire_id",
         *     referencedColumnName="id", 
         *     onDelete="SET NULL"
         *      )
         */
         private $universitaire;