Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OneToMany/ManyToOne SchemaException

I try to build a manyToOne relation for my Symfony2 application with Doctrine2. I get this error and I don't know why:

app/console doctrine:schema:create
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
ATTENTION: This operation should not be executed in an production enviroment.


  [Doctrine\DBAL\Schema\SchemaException]
  There is no column with name 'activityGroup' on table 'activity'.  

Those are the two classes: http://pastebin.com/Ev7Rwgxr

I think there actually IS activityGroup on the Activity class... so what does that error try to say?

Thanks!

like image 828
Stuck Avatar asked Jun 05 '11 00:06

Stuck


1 Answers

I got it...

the uniqueconstraints expect the real db field name which is activityGroup_id and not just activityGroup.

One can make sure what the field is called in the DB, by providing the JoinColumn.

So, an smart solution is:

    /**
     * @ORM\Entity
     * @ORM\Table(name="activity",
     *     uniqueConstraints={
     *         @ORM\UniqueConstraint(name="name_idx", columns={"activity_group_id", "name"}),
     *         @ORM\UniqueConstraint(name="sort_idx", columns={"activity_group_id", "sort_id"})
     *     }
     * )
     */
    class Activity
    {
        // ...

        /**
         * @ORM\ManyToOne(targetEntity="SeduceMe\SiteBundle\Entity\ActivityGroup", inversedBy="activities")
         * @ORM\JoinColumn(name="activity_group_id", referencedColumnName="id")
         */

        protected $activityGroup;
        //...
    }
like image 92
Stuck Avatar answered Nov 06 '22 10:11

Stuck