我尝试用Doctrine2为我的Symfony2应用程序建立一个manyToOne关系。我收到此错误,但不知道为什么:
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'.
这是两个类:http://pastebin.com/Ev7Rwgxr
我认为Activity类上实际上有一个activityGroup ...所以该错误试图说明什么?
谢谢!
最佳答案
我知道了...
uniqueconstraints期望真实的数据库字段名称为activityGroup_id
,而不仅仅是activityGroup
。
通过提供JoinColumn,可以确保在数据库中调用该字段。
因此,一个聪明的解决方案是:
/**
* @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;
//...
}
关于doctrine-orm - OneToMany/ManyToOne SchemaException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6240311/