2

I'm setting up a Symfony2 app and am trying to use Doctrine migrations. In this specific instance, I'm trying to add a new table, clients, for an entity, client, that I just created. This table does not exist in any form right now in the database.

When I run php app/console doctrine:migrations:diff, I get the following error:

[Doctrine\DBAL\Schema\SchemaException]                       
There is no column with name 'brand_id' on table 'clients'

Of course there is no column with that name, the table doesn't exist yet!

Shouldn't Doctrine recognize that there is no table and create it? For reference, here's my entity:

<?php

namespace RandomBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Client
 *
 * @ORM\Table(name="clients", indexes={@ORM\Index(name="brand_id", columns={"brand_id"})})
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 */
class Client
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

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

    /**
     * @var \RandomBundle\Entity\Brand
     *
     * @ORM\ManyToOne(targetEntity="RandomBundle\Entity\Brand")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="brand_id", referencedColumnName="id")
     * })
     */
    private $brand;

    /**
     * @var \RandomBundle\Entity\Project
     *
     * @ORM\OneToMany(targetEntity="RandomBundle\Entity\Project", mappedBy="client")
     */
    private $projects;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="updated_at", type="datetime", nullable=false)
     */
    private $updatedAt;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->projects = new \Doctrine\Common\Collections\ArrayCollection();
    }

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

    /**
     * Set name
     *
     * @param string $name
     * @return Client
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return Client
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Set brand
     *
     * @param \Ripplr3\RipplrBundle\Entity\Brand $brand
     * @return Client
     */
    public function setBrand(\RandomBundle\Entity\Brand $brand = null)
    {
        $this->brand = $brand;

        return $this;
    }

    /**
     * Get brand
     *
     * @return \RandomBundle\Entity\Brand 
     */
    public function getBrand()
    {
        return $this->brand;
    }

    /**
     * Add projects
     *
     * @param \RandomBundle\Entity\Project $projects
     * @return Client
     */
    public function addProject(\RandomBundle\Entity\Project $projects)
    {
        $this->projects[] = $projects;

        return $this;
    }

    /**
     * Remove projects
     *
     * @param \RandomBundle\Entity\Project $projects
     */
    public function removeProject(\RandomBundle\Entity\Project $projects)
    {
        $this->projects->removeElement($projects);
    }

    /**
     * Get projects
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getProjects()
    {
        return $this->projects;
    }
}
1
  • I had a similar error which was caused by /*. It means multiline comment started with /* instead of /**.
    – Čamo
    Feb 12, 2016 at 21:37

1 Answer 1

5

The unique point that i can see is the indexes declaration

 * @ORM\Table(name="clients", indexes={@ORM\Index(name="brand_id", columns={"brand_id"})})

i don't know if it's trying to create an index before create the table..
try delete it to see if the problem persists

2
  • i think you're doing on the right way.. /** * @ManyToOne(targetEntity="Address") * @JoinColumn(name="address_id", referencedColumnName="id") **/ (goo.gl/UipasD)
    – rLinhares
    Feb 26, 2015 at 18:39
  • Worked for me. Indexes where messing up the shema but where not detected by shema:validate
    – Gauthier
    Jan 25, 2018 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.