Reputation: 3992
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.
Upvotes: 27
Views: 61366
Reputation: 1735
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.
Upvotes: 0
Reputation: 375
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>
Upvotes: 5
Reputation: 614
<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
Upvotes: 42
Reputation: 77951
You're using the wrong refactoring operation. Try modifyDataType
Upvotes: 49