我正在尝试加载Doctrine实体,但它不断创建表而不考虑我提供的注释。我真正想做的是在$email
上设置一个独特的约束,但为了证明一些有趣的东西,我将$email
字段的大小更改为200。
我正在尝试运行./vendor/bin/doctrine orm:schema:create --dump-sql
。我得到以下输出:
CREATE TABLE user (
id INT AUTO_INCREMENT NOT NULL,
email VARCHAR(255) NOT NULL,
unverifiedEmail VARCHAR(255) DEFAULT NULL,
unverifiedEmailHash VARCHAR(255) DEFAULT NULL,
passwordHash VARCHAR(255) NOT NULL,
passwordResetHash VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
我把它格式化了,但没有改变。
这是vendor/redacted/user-entity/src/User.php
namespace Redacted\User\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer")
* @var int
*/
protected $id;
/**
* @ORM\Column(name="email", type="string", length=255, unique=true)
* @var string
*/
protected $email;
/**
* @ORM\Column(name="unverifiedEmail", type="string", length=255, nullable=true)
* @var string
*/
protected $unverifiedEmail;
/**
* @ORM\Column(name="unverifiedEmailHash", type="string", length=255, nullable=true)
* @var string
*/
protected $verifyEmailHash;
/**
* @var string
* At this time, http://php.net/manual/en/function.password-hash.php recommends using 255 length for hashes
* @ORM\Column(name="passwordHash", type="string", length=255)
*/
protected $passwordHash;
/**
* @var string
* @ORM\Column(name="passwordResetHash", type="string", length=255, nullable=true)
*/
protected $passwordResetHash;
/**
* @return mixed
*/
public function getUnverifiedEmail()
{
return $this->unverifiedEmail;
}
/**
* @param mixed $unverifiedEmail
*/
public function setUnverifiedEmail($unverifiedEmail)
{
$this->unverifiedEmail = $unverifiedEmail;
}
/**
* @return mixed
*/
public function getVerifyEmailHash()
{
return $this->verifyEmailHash;
}
/**
* @param mixed $verifyEmailHash
*/
public function setVerifyEmailHash($verifyEmailHash)
{
$this->verifyEmailHash = $verifyEmailHash;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* @return string
*/
public function getPasswordHash()
{
return $this->passwordHash;
}
/**
* @param string $passwordHash
*/
public function setPasswordHash($passwordHash)
{
$this->passwordHash = $passwordHash;
}
/**
* @return string
*/
public function getPasswordResetHash(): string
{
return $this->passwordResetHash;
}
/**
* @param string $passwordResetHash
*/
public function setPasswordResetHash(string $passwordResetHash)
{
$this->passwordResetHash = $passwordResetHash;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
public function toArray()
{
return [
'email' => $this->getEmail(),
'id' => $this->getId()
];
}
}
这是我的cli-config.php
。
require __DIR__.'/vendor/autoload.php';
$paths = array(__DIR__."/vendor/redacted/user-entity/src");
$isDevMode = false;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => 'redacted',
'dbname' => 'user'
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
$entityManager = EntityManager::create($dbParams, $config);
return ConsoleRunner::createHelperSet($entityManager);
我应该提到的另一件事是:在以前的几个项目中,我从未有过这方面的工作。我们在旅途中只有这么多,他们都有这个问题我正在解决它,但我确实在大量的ZF2项目中工作,但他们不共享这个设置方案。
答案 0 :(得分:0)
正如@malarzm上面所说,您可能需要清除缓存。以下是我在ZF2应用程序中更改学说配置时运行的命令:
rm -Rf data/DoctrineModule/cache/*
rm -Rf data/DoctrineORMModule/Proxy/*