1

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

}
ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • Have you added the timestampable annotation to the created at property? – Thomas K Aug 21 '14 at 19:21
  • @ThomasK yes I added the `Timestampable` annotation but I did some research and I though PostgreSQL handle timestamp different than MySQL as said [here](http://pointbeing.net/weblog/2008/03/mysql-versus-postgresql-adding-a-last-modified-column-to-a-table.html) or [here](http://www.revsys.com/blog/2006/aug/04/automatically-updating-a-timestamp-column-in-postgresql/) even if I check the columns at DB they have not default values in MySQL they have – ReynierPM Aug 21 '14 at 19:24
  • Just to be sure, can you post code for the createdAt property with annotations? – Thomas K Aug 21 '14 at 19:30
  • @ThomasK done already added to main post – ReynierPM Aug 21 '14 at 19:35
  • @ReynierPM, Have you added gedmo listener into services.yml? Example: https://gist.github.com/korotovsky/ebb1387e9a3e80a30a9c – Dmitrii Korotovskii Aug 21 '14 at 19:53

1 Answers1

7

You should enable timestampable in your config:

stof_doctrine_extensions:
    orm:
        default:
            timestampable: true
Thomas K
  • 6,076
  • 5
  • 39
  • 56
  • That was the error but now I'm getting this another error `Unable to find timestampable [created] as mapped property in entity - Sencamer\UsuarioBundle\Entity\Usuario` what I miss? the setter? – ReynierPM Aug 21 '14 at 20:03
  • @ReynierPM I've got the same error. Do you find a solution? – Kioko Kiaza Apr 28 '22 at 12:58