I have a custom table. Using the InstallSchema, I was able to add default values using:

    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
    'Created At'
    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
    'Updated At'

How can i achieve the same thing using the db schema xml file? :

<table comment="my table comment" engine="innodb" name="my_table_name" resource="default">
    <column name="created_at" nullable="false" xsi:type="datetime"/>
    <column name="updated_at" nullable="true" xsi:type="datetime"/>
<table comment="my table comment" engine="innodb" name="my_table_name" resource="default">
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>

use xsi:type="timestamp" . please implement and let me know if helpfull


Eventually, I found out. Please see:

<column name="created_at" nullable="false" xsi:type="datetime" default="CURRENT_TIMESTAMP" on_update="false"/>
<column name="updated_at" nullable="true" xsi:type="datetime" default="CURRENT_TIMESTAMP" on_update="true"/>

I needed to add this part: default="CURRENT_TIMESTAMP"

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.