我尝试了以下 yaml 代码:
columns:
created_time:
type: timestamp
notnull: true
default: default CURRENT_TIMESTAMP
在输出的sql语句中,该字段被视为日期时间而不是时间戳,我无法在其中定义当前时间戳...
如果我坚持使用时间戳来存储当前时间,如何在yaml中这样做?
最佳答案
如果您愿意牺牲一些可移植性(请参阅 description of columnDefinition attribute )来换取使用 MySQL 自动初始化 TIMESTAMP 的能力(请参阅 MySQL timestamp initialization ),那么您可以使用以下内容:
Yaml:
created_time:
type: datetime
columnDefinition: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
注释:
@ORM\Column(type="datetime", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
关于doctrine - 如何用 Doctrine 在 yaml 中定义当前时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2938655/