Home Liquibase - Add defaultValueComputed as CURRENT_TIMESTAMP to timestamp column
Reply: 0

Liquibase - Add defaultValueComputed as CURRENT_TIMESTAMP to timestamp column

user1277
1#
user1277 Published in June 19, 2018, 4:24 pm

I am using liquibase 3.5.3 to run liquibase update command on MySql 5.5. I have below changeSet to create a table which has a column as Created_Time that should have a default value as CURRENT_TIMESTAMP.

<changeSet author="authorName" id="AutoGeneratedId">
    <createTable tableName="aTable">
        <column autoIncrement="true" name="Id" type="INT">
            <constraints primaryKey="true"/>
        </column>
        <column name="Code" type="VARCHAR(45)"/>
        <column defaultValueComputed="CURRENT_TIMESTAMP" name="Created_Time" type="TIMESTAMP(19)"/>
    </createTable>
</changeSet>

While firing liquibase command it throws an exception as Unexpected error running Liquibase: Invalid default value for 'Created_Time' [Failed SQL: CREATE TABLE aTable (Id INT AUTO_INCREMENT NOT NULL, Code VARCHAR(45) NULL, Created_Time TIMESTAMP(19) DEFAULT NOW() NULL, CONSTRAINT PK_ATABLE PRIMARY KEY (Id))]

Liquibase is converting CURRENT_TIMESTAMP into NOW() that might be causing this issue.

Can some please provide me any solution or alternative to this issue?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.378888 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO