我在我的项目中使用symfony 2.4和postgresql。在我的语言环境中一切正常,但在服务器上它提供错误
"PHP message: PHP Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT p.id, p.username, p.email, p.isEmailConfirmed FROM CityDomGameBundle:Player p WHERE p.email = (:email) AND p.username != (:username)' in /var/...
错误发生在这里
$duplicatedEmails = $em->createQueryBuilder()
->select('p.id, p.username, p.email, p.isEmailConfirmed')
->from('CityDomGameBundle:Player', 'p')
->where('p.email = (:email)')
->andWhere('p.username != (:username)')
->setParameter(':email', $email)
->setParameter(':username', $username)
->getQuery()
->getResult();
我在我的表中添加了新列isEmailConfirmed
,所以看起来symfony无法识别它。如果我从p.isEmailConfirmed
语句中删除select
,则会有效。
这是实体代码
/**
* @var boolean $isEmailConfirmed
*
* @ORM\Column(name="isemailconfirmed", type="boolean")
*/
private $isEmailConfirmed;
和方法
/**
* @return boolean
*/
public function getIsEmailConfirmed()
{
return $this->isEmailConfirmed;
}
/**
* @param $isEmailConfirmed
* @return $this
*/
public function setIsEmailConfirmed($isEmailConfirmed)
{
$this->isEmailConfirmed = $isEmailConfirmed;
return $this;
}
我尝试cache:clear
,但没有帮助。任何想法?
更新
运行php app / console doctrine后:schema:update --force显示错误
[Doctrine\DBAL\Exception\NotNullConstraintViolationException]
An exception occurred while executing 'ALTER TABLE player ADD
isemailconfirmed BOOLEAN NOT NULL':
SQLSTATE[23502]: Not null violation: 7 ERROR: column
"isemailconfirmed" contains null values
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[23502]: Not null violation: 7 ERROR: column
"isemailconfirmed" contains null values
但此列的默认值为false
这是我添加列
alter table player add column isEmailConfirmed boolean default false;
答案 0 :(得分:0)
首先更新当前表格:
update player set isemailconfirmed = false where isemailconfirmed is null
或者像这样更改注释:
/**
* @var boolean $isEmailConfirmed
*
* @ORM\Column(name="isemailconfirmed", type="boolean", nullable=true)
*/
private $isEmailConfirmed;