如本文所述,我一直在尝试 为表列和我的schema.yml设置TIMESTAMP DEFAULT CURRENT_TIMESTAMP
默认值。created_at
updated_at
系统信息:
- Symfony 1.4.17 ,教义 1
- MySQL 5.6.10
- PHP 5.4
仔细阅读columnDefinition 文档,但无法正常工作。如文档中所述,columnDefinition
应在列名称之后设置属性。迁移数据库后,为这些列设置的默认值columnDefinition
不会添加到 MySQL 数据库中。
测试从type: timestamp
to更改type: datetime
,但datetime无法识别并运行迁移,显示错误消息。在文档中,所有关于 Timestamp 类型的引用都表明它应该被声明为:timestamp
- http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/defining-models.html
- http://symfony.com/legacy/doc/doctrine/1_2/en/04-Schema-Files
- https://doctrine.readthedocs.org/en/latest/en/manual/introduction-to-models.html
还测试了default
为这些列添加值属性,但它仍未在 MySQL 中设置。
架构.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
问题:
- 我的 schema.yml 有问题吗?
- 请您提供一个工作示例吗?