16
votes

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?

3

3 Answers

26
votes

You can increase the size of your column like this:

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

The schema defintion in your xml file doesn't allow <modifyDataType ... />.

The version of the xsd file should match the version of Liquibase you are using. The exception looks like you are using the xsd of version 1.9, see http://www.liquibase.org/documentation/xml_format.html

1
votes

In Oracle a TEMP column has to be used. Below is an example;

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
 <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

<changeSet id="example_id.001" author="Jasper">
    <preConditions>
        <not>
            <columnExists tableName="USERS" columnName="ADDRESS_TEMP"/>
        </not>
    </preConditions>
    <comment>change column ADDRESS_TEMP to 20 length</comment>

    <addColumn tableName="USERS ">
        <column name="ADDRESS_TEMP" type="varchar(2000)" />
    </addColumn>

    <sql>update USERS set ADDRESS_TEMP=ADDRESS</sql>
    <dropColumn tableName="USERS" columnName="ADDRESS" />

    <addColumn tableName="USERS">
        <column name="ADDRESS" type="${numeric_20_0}" >
            <constraints nullable="false"/>
        </column>
    </addColumn>

    <sql>update USERS set ADDRESS=ADDRESS_TEMP</sql>
    <dropColumn tableName="USERS" columnName="ADDRESS_TEMP" />
</changeSet>

</databaseChangeLog>