Engine23
blogBannerImage
By Engine23

Magento: Install/Upgrade script setting timestamp

If you need to create a custom table and have a "created at" or perhaps an "updated at" column on your custom table.  That is typically something you want.

In order to get this accomplished you need to have one extra parameter.

<?php
/* @var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;

$installer->startSetup();

$tableName = $installer->getTable('engine23_emaillog/entry');
$table = $installer->getConnection()->newTable($tableName)
    ->addColumn('created_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
        'nullable'  => false,
        'default'   => Varien_Db_Ddl_Table::TIMESTAMP_INIT,
        'comment'   => 'Created At',
    ), 'Created At')
->setComment('Email Log Table');
$installer->getConnection()->createTable($table);
$installer->endSetup();

The part that makes it work is: 'default' => Varien_Db_Ddl_Table::TIMESTAMP_INIT,

You can not use 'default' => 'CURRENT_TIMESTAMP', since it is NOT a valid parameter that Magento is looking for during validation.