我在使用 liquibase 更改 postgres 数据库中的列长度时遇到问题。
我有一个带有字段描述 varchar(300) 的表帐户。我想把它改成 varchar(2000)。
我在同一个文件中删除并重新创建了主键,所以我没有权限问题或架构/数据库名称或类似的东西。为了测试,我已经清除了数据表。
我在跑步
<changeSet author="liquibase" id="sample">
<modifyDataType
columnName="description"
newDataType="varchar(2000)"
schemaName="accountschema"
tableName="account"/>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
我收到此错误文本,但我无法理解问题。该列的唯一约束是非空约束,我成功添加了一个单独的更改日志来删除此约束(忽略我不明白为什么这会影响扩展字段长度的事实)。
谁能指出我做错了什么?
什么地方出了错:
任务 ':db-management:update' 执行失败。
liquibase.exception.LiquibaseException:运行 Liquibase 时出现意外错误:解析 src/main/changelog/db.changelog-accountdb-1.1.xml 的第 37 行第 38 列时出错:cvc-complex-type.2.4.a:发现无效内容元素“修改数据类型”。'{" 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}' 是预期的。
小智 26
您可以像这样增加列的大小:
<changeSet author="liquibase" id="sample">
<modifyDataType
columnName="description"
newDataType="varchar(2000)"
tableName="account"/>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
您的 xml 文件中的架构定义不允许<modifyDataType ... />.
xsd 文件的版本应与您使用的 Liquibase 版本相匹配。异常看起来您使用的是 1.9 版的 xsd,请参阅http://www.liquibase.org/documentation/xml_format.html
在 YAML 语法中,它看起来像:
databaseChangeLog:
- changeSet:
id: sample
author: liquibase
changes:
- modifyDataType:
columnName: description
newDataType: varchar(2000)
tableName: account
Run Code Online (Sandbox Code Playgroud)
对于 XML 语法,请参阅aashii 的回答。
| 归档时间: |
|
| 查看次数: |
25080 次 |
| 最近记录: |