How to define current timestamp in yaml with doctrine?

前端 未结 7 1115
灰色年华
灰色年华 2020-12-09 18:41

I tried the following yaml code:

columns:
  created_time:
    type: timestamp
    notnull: true
    default: default CURRENT_TIMESTAMP

In

7条回答
  •  青春惊慌失措
    2020-12-09 19:01

    If you are willing to sacrifice some portability (see description of columnDefinition attribute) for the ability to use MySQL's automatic initialization TIMESTAMP (see MySQL timestamp initialization), then you can use the following:

    Yaml:

      created_time:
        type: datetime
        columnDefinition: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    

    Annotation:

    @ORM\Column(type="datetime", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
    

提交回复
热议问题