用 liquibase 改变柱长

Alter column length with liquibase

我在使用 liquibase 更改 postgres 数据库中的列长度时遇到问题。

我有一个 table 帐户,其字段描述为 varchar(300)。我想把它改成 varchar(2000).

我已经在同一个文件中删除并重新创建了主键,所以我没有权限问题或架构/数据库名称或类似的问题。为了测试,我已经清除了 table 的数据。

我是运行

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

我收到了这个错误文本,但我无法理解这个问题。该列的唯一约束是非空约束,我成功添加了一个单独的变更日志以删除此约束(忽略我不明白为什么这会影响扩展字段长度的事实)。

谁能指出我做错了什么?

您的 xml 文件中的架构定义不允许 <modifyDataType ... />

xsd 文件的版本应与您使用的 Liquibase 版本相匹配。异常看起来您正在使用 1.9 版的 xsd,请参阅 http://www.liquibase.org/documentation/xml_format.html

您可以像这样增加列的大小:

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

在 Oracle 中必须使用 TEMP 列。下面是一个例子;

<?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>

在 YAML 语法中它看起来像:

databaseChangeLog:
  - changeSet:
      id: sample
      author: liquibase
      changes:
        - modifyDataType:
            columnName: description
            newDataType: varchar(2000)
            tableName: account

XML 语法参见