用 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>
我收到了这个错误文本,但我无法理解这个问题。该列的唯一约束是非空约束,我成功添加了一个单独的变更日志以删除此约束(忽略我不明白为什么这会影响扩展字段长度的事实)。
谁能指出我做错了什么?
- 失败:构建失败,出现异常。
出了什么问题:
任务“: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.
您的 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 语法参见 。
我在使用 liquibase 更改 postgres 数据库中的列长度时遇到问题。
我有一个 table 帐户,其字段描述为 varchar(300)。我想把它改成 varchar(2000).
我已经在同一个文件中删除并重新创建了主键,所以我没有权限问题或架构/数据库名称或类似的问题。为了测试,我已经清除了 table 的数据。
我是运行
<changeSet author="liquibase" id="sample">
<modifyDataType
columnName="description"
newDataType="varchar(2000)"
schemaName="accountschema"
tableName="account"/>
</changeSet>
我收到了这个错误文本,但我无法理解这个问题。该列的唯一约束是非空约束,我成功添加了一个单独的变更日志以删除此约束(忽略我不明白为什么这会影响扩展字段长度的事实)。
谁能指出我做错了什么?
- 失败:构建失败,出现异常。
出了什么问题:
任务“: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.
您的 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 语法参见