Timestampable does not work with ORM and PostgreSQL database

丶灬走出姿态 提交于 2019-12-11 12:23:55

问题


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]: Not null violation: 7 ERROR: null value in column "createdat" violates not-null constraint

Why? I'm using latest Symfony 2.5.3 and PostgreSQL 9.2.9. This is the complete error:

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]

Any advice?

Added entity

<?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;
    }

}

回答1:


You should enable timestampable in your config:

stof_doctrine_extensions:
    orm:
        default:
            timestampable: true


来源:https://stackoverflow.com/questions/25433550/timestampable-does-not-work-with-orm-and-postgresql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!