我正在尝试组织我的变更集,以便每个文件有一个变更集元素,正如 Liquibase Best Practices 所暗示的那样,但是当我尝试对我的 liquidbase xml 文件使用验证命令时出现以下错误。
liquibase: cvc-elt.1: Cannot find the declaration of element 'changeSet'. liquibase: Error thrown as a SAXException: Error parsing line 3 column 38 of ./1.xml: cvc-elt.1: Cannot find the declaration of element 'changeSet'.
我做错了什么?
master.xml:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<include file="./1.xml"/>
<include file="./2.xml"/>
</databaseChangeLog>
1.xml:
<?xml version="1.0" encoding="utf-8" ?>
<changeSet id="1" author="me">
<createTable
tableName="CLIENTS"
...
</createTable>
</changeSet >
最佳答案
每个包含的文件都需要具有与标准变更日志相同的 XML 根节点 - 因此您的 1.xml 应如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="1" author="me">
<createTable
tableName="CLIENTS"
...
</createTable>
</changeSet >
您可能还需要在主变更日志中指定包含的文件是相对于主变更日志的。
...
<include file="1.xml" relativeToChangelogFile="true"/>
...
是否需要这样做取决于您运行 liquibase 的方式。
关于xml - liquibase 命令行 : Cannot find the declaration of element 'changeSet' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23540464/