php - Symfony 3 : DateTime null even if it is specified in the Entity constructor -


i'm under symfony 3.0.6 use loadfixtures entity :

<?php  namespace appbundle\entity;  use doctrine\orm\mapping orm;  /**  * categorie  *  * @orm\table(name="categorie")  * @orm\entity(repositoryclass="appbundle\repository\categorierepository")  */ class categorie {     /**      * @var int      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @var string      *      * @orm\column(name="libelle", type="string", length=100)      */     private $libelle;      /**      * @var datetime      *      * @orm\column(name="created_at", type="datetime")      */     private $created_at;      /**      * @orm\manytoone(targetentity="\appbundle\entity\user", inversedby="categories")      * @orm\joincolumn(name="user_id", referencedcolumnname="id", ondelete="cascade")      */     private $user;      public function __construct()     {         $this->createdat = new \datetime('now');     }      /**      * id      *      * @return int      */     public function getid()     {         return $this->id;     }      /**      * set libelle      *      * @param string $libelle      *      * @return categorie      */     public function setlibelle($libelle)     {         $this->libelle = $libelle;          return $this;     }      /**      * libelle      *      * @return string      */     public function getlibelle()     {         return $this->libelle;     }      /**      * set user      *      * @param \appbundle\entity\user $user      *      * @return categorie      */     public function setuser(user $user = null)     {         $this->user = $user;          return $this;     }      /**      * user      *      * @return \appbundle\entity\user      */     public function getuser()     {         return $this->user;     }      /**      * set createdat      *      * @param datetime $createdat      */     public function setcreatedat($createdat)     {         $this->createdat = $createdat;     }      /**      * createdat      *      * @return datetime      */     public function getcreatedat()     {         return $this->createdat;     } } 

and when try insert values :

public function loadcategorie(objectmanager $manager, $user) {     $alib = array('categ1','categ2','categ3','categ4','categ5','categ6','categ7');      foreach($alib $catp)     {         $cat = new categorie();         $cat->setlibelle("[".$user->getusername()."] ".$catp);         $cat->setuser($user);         $manager->persist($cat);     }     $manager->flush(); } 

i have error :

[doctrine\dbal\exception\notnullconstraintviolationexception] exception occurred while executing 'insert categorie (libelle, created_at, user_id) values (?, ?, ?)' params ["[cyriladmin] categ1", null, 1]: sqlstate[23000]: integrity constraint violation: 1048 column 'created_at' cannot null

any ideas ?

you have bug in entity: private $created_at; vs $this->createdat = new \datetime('now'); <- different variables names.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -