1

I'm using magento Magento2.3.4, I tried to add new column with datetime type and default value of current datetime like this:

$columns['created_time'] = [
                             'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                             'nullable' => true,
                             'comment' => 'Created Time',
                             'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT
                           ];

but i always got an error:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_time'

2 Answers 2

1

Change your type to timestamp,

$columns['created_time'] = [
      'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
      'nullable' => true,
      'comment' => 'Created Time',
      'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT
];
1
  • i need the type in datetime format
    – jojo
    Feb 13, 2020 at 7:26
0
<column xsi:type="datetime" name="created_at" on_update="false"
                nullable="false" default="CURRENT_TIMESTAMP" comment="Created Time"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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