0

In liquibase, I created a table, one of column is like below

<column name="identifier" type=""varchar2(50)">
    <constraint nullable="false"/>
</column>

This changeset is already executed

Now I need to set this column as

<constraint nullable="true"/>  

I am using MySql

Thomas
  • 1,008
  • 3
  • 16
  • 34
gourav
  • 33
  • 7

2 Answers2

0

If you want to change a column to nullable='true' in Liquibase, you can use the modifyColumn tag.

<modifyColumn tableName="table_name">
    <column name="identifier" type="varchar2(50)">
        <constraint nullable="true"/>
    </column>
</modifyColumn>

Note: in Mysql, the equivalent for varchar2 is varchar; So ur modifyColumn tag should look like this:

<modifyColumn tableName="table_name">
    <column name="identifier" type="varchar(50)">
        <constraint nullable="true"/>
    </column>
</modifyColumn>
Tarik
  • 161
  • 4
  • This is not working, I don't think there is modifyColumn in liquibase. – gourav Feb 13 '23 at 12:13
  • u need to check this link https://forum.liquibase.org/t/modifycolumn-vs-modifydatatype/1175/2 The reason that modifyColumn was removed from 2.0 was because it was too generic and didn’t provide liquibase with enough information on what you were trying to do for it to correctly generate the SQL you need. ModifyDataType is a replacement for much of what people tried to use modifyColumn for, but like you mention it doesn’t cover everything. – Tarik Feb 13 '23 at 12:23
0
<modifyDataType 
    tableName="unspecified" 
    columnName="identifier" 
    newDataType="VARCHAR(50) NOT NULL"/>

modifyDataType can be used while preserving data type and adding NOT NULL constraint

orikosaki
  • 176
  • 1
  • 6