Suba
Suba

Reputation: 69

Symfony2: The target entity cannot be found when update schema

Profile Entity

<?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;

Contact Entity:

<?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;

When I update schema via command line i received the following error message

The target entity Student\ProfileBundle\Entity\Contact can not found in Student\ProfileBundle\Entity\Profile#contact

Please help me .

Upvotes: 0

Views: 733

Answers (1)

Vera
Vera

Reputation: 742

There is a namespace error - entities are located in different bundles. You should provide an absolute path to entity instead of relative:

for Profile#contact relation:

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

protected $contact;

and for Contact#profile one:

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

protected $profile;

Upvotes: 1

Related Questions