Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter column length with liquibase

Tags:

liquibase

I am having problems changing a column length in my postgres db with liquibase.

I have a table account with a field description varchar(300). I want to change it to varchar(2000).

I have dropped and recreated the primary key in the same file so I don't have permissions issues or schema / db names or anything like this. For the sake of testing I have cleared the table of data.

I am running

<changeSet author="liquibase" id="sample">
    <modifyDataType
        columnName="description"
        newDataType="varchar(2000)"
        schemaName="accountschema"
        tableName="account"/>
</changeSet>

I'm getting this error text but I can't understand the issue. The only constraint the column had was a not null constraint and I successfully added a separate changelog to remove this constraint (ignoring the fact I don't see why this would affect extending the length of the field).

Can anyone point to what I am doing wrong?

  • FAILURE: Build failed with an exception.
  • What went wrong:

    Execution failed for task ':db-management:update'.

    liquibase.exception.LiquibaseException: Unexpected error running Liquibase: Error parsing line 37 column 38 of src/main/changelog/db.changelog-accountdb-1.1.xml: cvc-complex-type.2.4.a: Invalid content was found starting with element 'modifyDataType'. One of '{"http://www.liquibase.org/xml/ns/dbchangelog/1.9":validCheckSum, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":preConditions, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":tagDatabase, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":comment, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":createTable, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropTable, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":createView, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":renameView, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropView, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":insert, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addColumn, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":sql, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":createProcedure, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":sqlFile, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":renameTable, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":renameColumn, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropColumn, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":modifyColumn, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":mergeColumns, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":createSequence, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":alterSequence, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropSequence, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":createIndex, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropIndex, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addNotNullConstraint, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropNotNullConstraint, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addForeignKeyConstraint, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropForeignKeyConstraint, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropAllForeignKeyConstraints, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addPrimaryKey, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropPrimaryKey, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addLookupTable, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addAutoIncrement, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addDefaultValue, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropDefaultValue, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":addUniqueConstraint, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":dropUniqueConstraint, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":customChange, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":update, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":delete, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":loadData, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":executeCommand, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":stop, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":rollback, "http://www.liquibase.org/xml/ns/dbchangelog/1.9":modifySql}' is expected.

like image 403
gringogordo Avatar asked May 19 '16 09:05

gringogordo


1 Answers

You can increase the size of your column like this:

<changeSet author="liquibase" id="sample">
    <modifyDataType
        columnName="description"
        newDataType="varchar(2000)"
        tableName="account"/>
</changeSet>
like image 132
aashii Avatar answered Sep 21 '22 15:09

aashii