3
votes

I have created a table with name person and added a column 'phone_number' using liquibase changeset. But now I want to add a default value for it. but it did not work, so far I have tried this:

<addDefaultValue columnName="phone_number"
                 defaultValue="+923331234567"
                 tableName="person"/>

and

<changeSet author="haseeb" id="20160413123500">
    <update tableName="person">
        <column name="phone_number" type="varchar(255)" defaultValue="+923331234567"/>
    </update>
</changeSet>

and

<changeSet author="haseeb" id="20160413123501">
    <update tableName="person">
        <column name="phone_number" type="varchar(255)" value="+923331234567"/>
</update>

Can anyone point out where I did wrong and also would adding default value will add value to previously added rows?

3

3 Answers

3
votes

try this

<addDefaultValue columnName="phone_number"
             defaultValue="+923331234567"
             tableName="person" columnDataType="varchar(255)"/>
2
votes

Try this:

<changeSet author="haseeb" id="20160413123501">
    <modifyDataType
        columnName="phone_number"
        newDataType="varchar(255)"
        defaultValue="+923331234567"
        tableName="person"/>
    <comment>Change default value</comment>
</changeSet>
0
votes

This is worked for expression:

- addDefaultValue:
    tableName: RT_STAGE
    columnName: CREATED_DATE
    defaultValueComputed: now()

and this for boolean:

- addDefaultValue:
    tableName: RT_STAGE
    columnName: FINAL
    defaultValueBoolean: false