gpt4 book ai didi

php - symfony2 中未识别的新列未捕获的异常 'Doctrine\ORM\Query\QueryException

转载 作者:行者123 更新时间:2023-11-29 13:47:50 25 4
gpt4 key购买 nike

我在我的项目中使用 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 似乎无法识别它。如果我从 select 语句中删除 p.isEmailConfirmed,它将起作用。

这是实体代码

 /**
* @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;

最佳答案

首先更新当前表:

update player set isemailconfirmed = false where isemailconfirmed is null

或者像这样更改注释:

/**
* @var boolean $isEmailConfirmed
*
* @ORM\Column(name="isemailconfirmed", type="boolean", nullable=true)
*/
private $isEmailConfirmed;

关于php - symfony2 中未识别的新列未捕获的异常 'Doctrine\ORM\Query\QueryException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45584982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com