6

I am updating my table structure and everything work good, but default value for column created_at is 0000-00-00 00:00:00 again and again.

I want it to be equal to current time (CURRENT_TIMESTAMP);

Here is my current code:

$table->addColumn($tableBanners, 'created_at', [
    'type'     => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
    'nullable' => false,
    'comment'  => 'created_at',
    'default'  => 'CURRENT_TIMESTAMP'
]);
6

On 'default' section, change to Varien_Db_Ddl_Table::TIMESTAMP_INIT. So that:

'default'  => Varien_Db_Ddl_Table::TIMESTAMP_INIT

Ref: https://code007.wordpress.com/2014/04/26/magento-how-to-create-a-timestamp-table-column-with-current_timestamp-as-default-value/

  • 1
    Yes, I've just found this solution :) – Kyrylo Romantsov Aug 17 '17 at 10:09
  • Please accept my answer then :) – PY Yick Aug 17 '17 at 10:10
  • 3
    And for updated_at columns use Varien_Db_Ddl_Table::TIMESTAMP_INIT_UPDATE as default. – clockworkgeek Mar 23 '18 at 13:21
  • @clockworkgeek : Actually now it seems to be Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE, thanks for the hint ! – rou6e Feb 27 at 16:11
  • @AdrienFERREIRAAlioze - Yes it's all different now with Magento 2. – clockworkgeek Mar 1 at 9:17
0

You can use these for equal value for current timestamp

date('Y-m-d G:i:s')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.