Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to insert values in a table using sequence in Liquibase

I want to use sequence_name.NEXTVAL to automatically compute a column's value in liquibase. The backend database is postgresql. I tried to use "valueComputed" attribute as shown in this link. But it is not computing value using sequence and column's value is null at the time of insertion. How can we auto increment a column in liquibase using a sequence? Thank you for your help in advance.

My code is as below :

    <changeSet id="20151020000" author="jhipster">      

    <createSequence cycle="false" incrementBy="1" maxValue="1000"  minValue="50" sequenceName="seq_name" startValue="50"/>

    <createTable tableName="tablename">
                <column name="id" type="bigint" valueComputed ="seq_name.NEXTVAL">
                    <constraints primaryKey="true" nullable="false"/>
                </column>
   </createTable>
like image 436
somename Avatar asked Dec 08 '22 00:12

somename


1 Answers

This worked for me:

<createTable tableName="tablename">
    <column name="id" type="bigint" defaultValueSequenceNext="seq_name">
        <constraints primaryKey="true" nullable="false"/>
    </column>
</createTable>
like image 141
dfche Avatar answered Dec 11 '22 11:12

dfche