doctrine - 如何用 Doctrine 在 yaml 中定义当前时间戳?

标签 doctrine timestamp yaml

我尝试了以下 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/

相关文章:

c++ - 如何在 OpenCV 中以编程方式在 YAML 中编写注释?

mysql - 什么是 MySQL FOUND_ROWS() 方法的 SQL 等价物?

php - symfony2 : ContextErrorException on production server "Erroneous data format for unserializing"

mysql - Doctrine 默认值与空插入

mysql - cakePHP 时间戳字段未正确保存

python - 如何在 Ansible 的 do-until 循环中指定多个条件

php - 按 i18n 字段对 symfony admin-generator-list 进行排序

java - 此特定格式的时间戳

javascript - 在javascript中将时间戳转换为特定的日期格式

yaml - 如何在yaml的多行字符串中转义哈希(#)字符?