2

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

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?
Community
  • 1
  • 1
xtrm
  • 966
  • 9
  • 22
  • Thank you for the edits j0k, a lot better now :) – xtrm Jun 20 '13 at 08:29
  • If you just leave in your schema `actAs: Timestampable` Doctrine will automatically add the columns `created_at` and `updated_at` and will take care of the proper handling. You don't have to worry about that. – Michal Trojanowski Jun 20 '13 at 08:36
  • Thats true Michal, however I need to add the default values for those columns since sometimes I send raw SQLs without using Doctrine. I can perfectly add those default values ALTERING all the tables with an MySQL gui Editor with a simple SQL loop, but still would like to have all my information in the schema.yml if possible. – xtrm Jun 20 '13 at 08:51

0 Answers0