在'AppBundle \ Entity \ User#bitcoinWallet'中找不到目标实体

时间:2016-10-16 04:27:55

标签: php symfony orm doctrine-orm annotations

我正在使用Symfony 3,并希望将实体User映射为多个BitcoinWallet

我的AppBundle\Entity\User.php看起来像这样:

<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User extends BaseUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @var string
 * @ORM\Column(type="string", length=255, nullable=true)
 */
protected $firstName;
/**
 * @var string
 * @ORM\Column(type="string", length=255, nullable=true)
 */
protected $lastName;

/**
 * @ORM\Column(type="string", length=255, nullable=true)
 * @Assert\File(maxSize="2048k")
 * @Assert\Image(mimeTypesMessage="Please upload a valid image.")
 */
protected $profilePicture;

/**
 * @Assert\Email(
 *     message = "The email '{{ value }}' is not a valid email.",
 *     checkMX = true
 * )
 */
protected $email;

protected $emailCanonical;

/**
 * @ORM\ManyToOne(targetEntity="BitcoinBundle\Entity\BitcoinWallet")
 * @ORM\JoinColumn(name="bitcoin_wallet", referencedColumnName="id")
 */
protected $bitcoinWallet;

/**
 * @var \DateTime $created
 *
 * @Gedmo\Timestampable(on="create")
 * @ORM\Column(type="datetime")
 */
private $created;

/**
 * @var \DateTime $updated
 *
 * @Gedmo\Timestampable(on="update")
 * @ORM\Column(type="datetime")
 */
private $updated;

我的BitcoinBundle\Entity\BitcoinWallet位于以下位置:

<?php
namespace BitcoinBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="BitcoinBundle\Entity\BitcoinWalletRepository")
 * @ORM\Table(name="bitcoin_wallet")
 * @ORM\HasLifecycleCallbacks
 */
class BitcoinWallet
{

/**
 * in use    = The address is being used for some reason
 * available = the address is free
 */
const STATE_IN_USE    = 0;
const STATE_AVAILABLE = 1;

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;
/**
 * @ORM\Column
 * @ORM\GeneratedValue(strategy="NONE")
 * @ORM\Column(type="string", length=34, unique=true)
 */
private $address;

/**
 * @ORM\Column(name="state", type="smallint")
 */
private $state;

/**
 * @ORM\Column(name="balance", type="decimal", precision=16, scale=8)
 */
private $balance = 0;

/**
 * @ORM\Column(name="updated_at", type="datetime")
 */
private $updated_at;

运行php bin/console doctrine:schema:update --force后数据库已成功更新,但现在我收到此消息:

在'AppBundle \ Entity \ User#bitcoinWallet'中找不到目标实体BitcoinBundle \ Entity \ BitcoinWallet。

1 个答案:

答案 0 :(得分:0)

看起来实体声明不正确。

BitcoinBundle\Entity\BitcoinWallet中应该是ManyToOne声明:

 /**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 * @ORM\ManyToOne(targetEntity="UserBundle\Entity\User", inversedBy="bitcoin_wallet")
 */
protected $id;

ManyToOne中的AppBundle\Entity\User.php陈述是错误的。