实体更新后的Doctrine2仍然生成旧数据库表 [英] Doctrine2 after entity update still generate old database table
问题描述
我学习教义2。问题是:我刚刚更新了我的实体类。旧版本的实体由$ id,$ name和$ username字段组成。在下面这个更新之后,我运行命令原则:generate:entities Acme,doctrine:update:schema等,但结果仍然是只有3个字段的旧表。看起来像旧的元数据被保存在某个地方。有人可以向我提供信息我做错了什么?为什么我得到旧的数据库表而不是新的数据库表?甚至如何解决我的问题?
Im learning doctrine2. Problem is: I have just updated my entity class. Old version of entity consisted of $id, $name and $username fields. After this update below, I run command doctrine:generate:entities Acme, doctrine:update:schema and etc., but result is still old table with only 3 fields. It looks like old meta-data is saved somewhere. Can someone provide me with information what Im doing wrong ? And why I get old database table instead of new one ? And even how to solve my problem ?
namespace Acme\DemoBundle\Entity;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Table(name="user")
* @ORM\Entity
*/
class User implements UserInterface, EquatableInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=50)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=50)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="roles", type="string", length=50)
*/
private $roles;
/**
* @var array
*
* @ORM\Column(name="apikey", type="array")
*/
private $apiKey;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=10)
*/
private $salt;
function __construct($apiKey, $id, $password ,$roles , $salt, $username)
{
$this->apiKey = $apiKey;
$this->id = $id;
$this->password = $password;
$this->roles = $roles;
$this->salt = $salt;
$this->username = $username;
}
/**
* The equality comparison should neither be done by referential equality
* nor by comparing identities (i.e. getId() === getId()).
*
* However, you do not need to compare every attribute, but only those that
* are relevant for assessing whether re-authentication is required.
*
* Also implementation should consider that $user instance may implement
* the extended user interface `AdvancedUserInterface`.
*
* @param UserInterface $user
*
* @return bool
*/
public function isEqualTo(UserInterface $user)
{
if (!$user instanceof User) {
return false;
}
if ($this->password !== $user->getPassword()) {
return false;
}
if ($this->salt !== $user->getSalt()) {
return false;
}
if ($this->username !== $user->getUsername()) {
return false;
}
return true;
}
/**
* Returns the roles granted to the user.
*
* <code>
* public function getRoles()
* {
* return array('ROLE_USER');
* }
* </code>
*
* Alternatively, the roles might be stored on a ``roles`` property,
* and populated in any number of different ways when the user object
* is created.
*
* @return Role[] The user roles
*/
public function getRoles()
{
return $this->roles;
}
/**
* Returns the password used to authenticate the user.
*
* This should be the encoded password. On authentication, a plain-text
* password will be salted, encoded, and then compared to this value.
*
* @return string The password
*/
public function getPassword()
{
return $this->password;
}
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*
* @return string|null The salt
*/
public function getSalt()
{
return $this->salt;
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
return $this->username;
}
/**
* @return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* @param string $apiKey
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
}
推荐答案
如果旧元数据被保存你必须清除缓存
If the old metadata is saved You have to clear cache
doctrine:cache:clear-metadata Clears all metadata cache for an entity manager
doctrine:cache:clear-query Clears all query cache for an entity manager
doctrine:cache:clear-result Clears result cache for an entity manager
这篇关于实体更新后的Doctrine2仍然生成旧数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!