timestamable不适用于ORM和PostgreSQL数据库


Timestampable does not work with ORM and PostgreSQL database

我在我的实体中添加了对Timestampable的支持如下:use Gedmo'Timestampable'Traits'TimestampableEntity;。我通过运行doctrine:schema:update --force更新了我的DB,但每当我尝试插入新记录时,我都会得到此消息:

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "createdat" violation Not -null constraint

为什么?我使用最新的Symfony 2.5.3和PostgreSQL 9.2.9。这是完整的错误:

执行INSERT INTO usuarios_externos时发生异常。常用情况(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、direction、deletedAt、createdAt、updatedAt、pais_id、estado_id、municipio_id、ciudad_id、parroquia_id) VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' 与params["reynier"、"reynier","reynierpm@gmail.com"、"reynierpm@gmail.com","假","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;
    }
}

您应该在配置中启用timestamable:

stof_doctrine_extensions:
    orm:
        default:
            timestampable: true