时间戳记不适用于ORM和PostgreSQL数据库 [英] Timestampable does not work with ORM and PostgreSQL database
问题描述
我在实体中添加了对 Timestampable
的支持,如下所示:使用Gedmo\Timestampable\Traits\TimestampableEntity;
。我已经通过运行 doctrine:schema:update --force
更新了数据库,但是任何时候我尝试插入新记录时都会收到以下消息:
I added support for Timestampable
in my entity as follow: use Gedmo\Timestampable\Traits\TimestampableEntity;
. I have updated my DB by running doctrine:schema:update --force
but any time I try to insert a new record I get this message:
SQLSTATE [23502]:不为null违反:7错误: createdat列中的null值违反了非null约束
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "createdat" violates not-null constraint
为什么?我正在使用最新的Symfony 2.5.3和PostgreSQL 9.2.9。这是完全错误:
Why? I'm using latest Symfony 2.5.3 and PostgreSQL 9.2.9. This is the complete error:
执行'INSERT INTO usuarios_externos.usuarios(用户名,username_canonical,电子邮件,email_canonical,已启用,盐,密码,last_login,锁定,过期,expires_at,confirmation_token,password_requested_at,
个角色,凭据已过期,凭据_expire_at,id,角色,correo_alternativo,telefono,telefono_movil,传真,pagina_web,版本,deleteAt,creatis,atAt,updateAt estado_id,municipio_id,ciudad_id,parroquia_id)值(?,
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'与参数[ reynier, reynier, reynierpm@gmail.com, reynierpm @ gmail.com, false, hhm95if1uog88koggos48csk48k0w80,
sVzbTOHgZzhU92zPHBFsVG3GqV + DO5xvXxvNdC5 / GVJ / Hnvlm8rBsNDsIgPKYXdZ4NcnA, n, N :0:{}, false,null,3, true, reynierpm1@gmail.com, 021245678999 ,,,, sadasdasd,
null,null,null,23,1,1,1,1,22]
An exception occurred while executing 'INSERT INTO usuarios_externos.usuarios (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, locked, expired, expires_at, confirmation_token, password_requested_at, roles, credentials_expired, credentials_expire_at, id, persona, correo_alternativo, telefono, telefono_movil, fax, pagina_web, direccion, deletedAt, createdAt, updatedAt, pais_id, estado_id, municipio_id, ciudad_id, parroquia_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["reynier", "reynier", "reynierpm@gmail.com", "reynierpm@gmail.com", "false", "hhm95if1uog88koggos48csk48k0w80", "sVzbTOHgZzhU92zPHBFsVG3GqV+DO5xvXxvNdC5/GVJ/Hnvlm8rBsNDsIgPKYXdZ4NcnONqXnrOB6UR+lAluAw==", null, "false", "false", null, null, null, "a:0:{}", "false", null, 3, "true", "reynierpm1@gmail.com", "021245678999", "", "", "", "sadasdasd", null, null, null, 23, 1, 1, 1, 22]
有任何建议吗?
已添加实体
<?php
use FOS\UserBundle\Model\User as BaseUser;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="usuarios_externos.usuarios", schema="usuarios_externos")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Usuario extends BaseUser
{
....
/**
* @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;
/**
* @ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
protected $deletedAt;
....
public function getCreated()
{
return $this->created;
}
public function getUpdated()
{
return $this->updated;
}
public function setDeletedAt($deletedAt)
{
$this->deletedAt = $deletedAt;
}
public function getDeletedAt()
{
return $this->deletedAt;
}
}
推荐答案
您应该在配置中启用时间戳记:
You should enable timestampable in your config:
stof_doctrine_extensions:
orm:
default:
timestampable: true
这篇关于时间戳记不适用于ORM和PostgreSQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!