Symfony 1.4 Doctrine 1 Yaml, cannot define default

2019-07-24 03:59发布

问题:

I have been trying to set TIMESTAMP DEFAULT CURRENT_TIMESTAMP default values for the table columns created_at and updated_at in my schema.yml as explained in this post.

System Info:

  • Symfony 1.4.17, Doctrine 1
  • MySQL 5.6.10
  • PHP 5.4

Carefully read the columnDefinition documentation but couldnt get it to work. As stated in the documentation, columnDefinition attribute should be set after the name of the column. After making a migration of the database, the default values set in columnDefinition for those columns are not added to the MySQL Database.

Tested changing from type: timestamp to type: datetime, but datetime its not recognized and running a migrate up, shows an an error message. In the documentation all references about Timestamp type shows it should be declared as: 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

Also tested adding a default value attribute for those columns, but its still not set in 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 table: tbmdtest005 created in the database after the migration:

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

Questions:

  • Is something wrong in my schema.yml?
  • Please could you provide a working example?