Doctrine Symfony 1.4.1 Yaml,无法定义默认时间戳值

Doctrine Symfony 1.4.1 Yaml,无法定义默认时间戳值,doctrine,timestamp,symfony-1.4,yaml,doctrine-1.2,Doctrine,Timestamp,Symfony 1.4,Yaml,Doctrine 1.2,我一直在尝试为我的schema.yml中创建的和更新的表列设置默认值 系统信息: Tbmdtest005: connection: md_test columns: id: type: integer(8) fixed: false unsigned: false primary: true autoincrement: true actAs: Timestampable: created:

我一直在尝试为我的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
  • Symfony 1.4.17,条令1
  • MySQL 5.6.10
  • PHP5.4
仔细阅读这本书,但无法使它发挥作用。如文档中所述,
columnDefinition
属性应设置在列名称之后。迁移数据库后,
columnDefinition
中为这些列设置的默认值不会添加到MySQL数据库中。

测试了从
类型:timestamp
更改为
类型:datetime
,但无法识别datetime,并且运行向上迁移时会显示错误消息。在文档中,所有关于时间戳类型的引用都表明它应该声明为:
Timestamp

还测试了为这些列添加一个
default
value属性,但它仍然没有在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
问题:

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
  • 我的schema.yml有什么问题吗
  • 请你提供一个有效的例子好吗

感谢您对j0k的编辑,现在好多了:)如果您只是在模式中离开
actAs:timestable
原则将自动添加列
创建的列和
更新的列,并注意正确的处理。你不必担心,这是真的,但是我需要为那些列添加默认值,因为有时我发送原始SQL时没有使用原则。我可以通过一个MySQL gui编辑器和一个简单的SQL循环完美地添加这些默认值,改变所有的表,但是如果可能的话,我仍然希望所有的信息都在schema.yml中。