Doctrine 2.1 - datetime column default value

前端 未结 7 1218
小蘑菇
小蘑菇 2020-12-30 18:51

Could someone tell me how to add default value on datetime column? I can\'t do this like this:

protected $registration_date = date(\"Y-m-d H:i:s\", time());
         


        
7条回答
  •  隐瞒了意图╮
    2020-12-30 19:18

    I think, the best way to accomplish autofill for datetime is to make like that:

    * @ORM\Column(type="datetime", options={"default"="CURRENT_TIMESTAMP"})
    

    Putting logic to constructor isn't right solution, because setting default values are SQL client responsibility. If you decide no longer use ORM - you will lost business logic. Plus, if using constructor you won't be able to add default timestamps to datetime attributes for existing rows.

提交回复
热议问题