25

I want to update the type of a column named "password". At the moment it has type NVARCHAR(40) and I want it to be of type NVARCHAR(64). This is what I did:

<changeSet id="1 - change password length" author="chris311">
    <update tableName="tablename">
        <column name="password" type="NVARCHAR(64)"/>
    </update>
</changeSet>

What else is there to do? Because this obviously does not change anything in the DB.

cheffe
  • 9,345
  • 2
  • 46
  • 57
Chris311
  • 3,794
  • 9
  • 46
  • 80

4 Answers4

43

You're using the wrong refactoring operation. Try modifyDataType

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
39
<changeSet id="increase-password-length" author="martin">
  <modifyDataType tableName="tablename" columnName="password" newDataType="NVARCHAR(64)"/>
</changeSet>

You can check out http://www.liquibase.org/documentation/changes/modify_data_type.html for more documentation

Martin Rugadya
  • 584
  • 7
  • 14
5

Or you can do by using sql tag:

<changeSet author="liquibase-sql" id="example-sql" context="migrate">
    <sql dbms="mysql">
      ALTER TABLE tablename MODIFY COLUMN password NVARCHAR(64)
    </sql>
</changeSet>
Huỳnh Tú
  • 355
  • 4
  • 6
0

TL;DR;

For MySQL: Use addNotNullConstraint

Explanation:

On MySQL, the pitfall is that modifyDataType is going to change the null constraint to nullable (the default). Liquibase is going to warn you about this and not doing the change. It will even give you a hint to do it by using SQL.

Using the addNotNullConstraint, in MySQL you need to give the datatype too, so you can keep your constraint and change the type.

Roeland Van Heddegem
  • 1,623
  • 2
  • 20
  • 35