Symfony2:更新架构时找不到目标实体

时间:2015-01-29 07:24:54

标签: symfony doctrine-orm

个人资料实体

<?php

namespace Student\ProfileBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * Profile
 *
 * @ORM\Table(name="sf2_profile")
 * @ORM\Entity(repositoryClass="Student\ProfileBundle\Entity\ProfileRepository")
 */
class Profile
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
    * @ORM\OneToOne(targetEntity="Contact", mappedBy="profile")
    */

    protected $contact;

联系实体:

<?php

namespace Student\ContactBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Contact
 *
 * @ORM\Table(name="sf2_contact")
 * @ORM\Entity(repositoryClass="Student\ContactBundle\Entity\ContactRepository")
 */
class Contact
{

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
    * @ORM\OneToOne(targetEntity="Profile", inversedBy="contact")
    * @ORM\JoinColumn(name="profile_id", referencedColumnName="id")
    */

    protected $profile;

当我通过命令行更新架构时,我收到以下错误消息

  

在Student \ ProfileBundle \ Entity \ Profile #contact

中找不到目标实体Student \ ProfileBundle \ Entity \ Contact

请帮帮我。

1 个答案:

答案 0 :(得分:1)

存在名称空间错误 - 实体位于不同的包中。您应该提供实体的绝对路径而不是相对路径:

for Profile#contact relation:

/**
* @ORM\OneToOne(targetEntity="Student\ContactBundle\Entity\Contact", mappedBy="profile")
*/

protected $contact;

和联系人#个人资料一:

/**
* @ORM\OneToOne(targetEntity="Student\ProfileBundle\Entity\Profile", inversedBy="contact")
* @ORM\JoinColumn(name="profile_id", referencedColumnName="id")
*/

protected $profile;
相关问题