OneToMany / ManyToOne SchemaException

I am trying to build a ManyToOne relationship 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'. 

These are two classes: http://pastebin.com/Ev7Rwgxr

I think that there is actually an ActivityGroup in the Activity class ... so what is this error trying to say?

Thanks!

+6
source share
1 answer

I understood...

uniqueconstraints expects the true name of the db field to be equal to activityGroup_id , not just activityGroup .

You can make sure that the field is called in the database by providing JoinColumn.

So the smart solution:

  /** * @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; //... } 
+8
source

Source: https://habr.com/ru/post/889797/


All Articles