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!
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;
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With