我一直在尝试为表格列 TIMESTAMP DEFAULT CURRENT_TIMESTAMP
和 created_at
设置 updated_at
默认值在我的 schema.yml 中,如post中所述。
系统信息:
仔细阅读columnDefinition documentation,但无法让它发挥作用。如文档中所述,应在列名称后面设置columnDefinition
属性。在迁移数据库之后,columnDefinition
中为这些列设置的默认值不会添加到MySQL数据库中。
经过测试,从type: timestamp
更改为type: datetime
,但 datetime 无法识别并运行迁移,显示错误消息。在文档中,有关时间戳类型的所有引用都显示它应声明为:timestamp
还测试了为这些列添加default
值属性,但它仍未在MySQL中设置。
的schema.yml:
Tbmdtest005:
connection: md_test
columns:
id:
type: integer(8)
fixed: false
unsigned: false
primary: true
autoincrement: true
actAs:
Timestampable:
created:
name: created_at
columnDefinition: TIMESTAMP DEFAULT CURRENT_TIMESTAMP
default: CURRENT_TIMESTAMP
type: timestamp
format: Y-m-d H:i:s
options:
notnull: false
required: false
updated:
name: updated_at
columnDefinition: TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
default: CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
type: timestamp
format: Y-m-d H:i:s
options:
notnull: false
required: false
迁移后在数据库中创建的 MySQL表: tbmdtest005
:
CREATE TABLE `tbmdtest005` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci
问题: