问题
I'm trying to organize my changesets such that there is one changeset element per file, as implied by the Liquibase Best Practices, but I get the following error when i try to use the validate command on my liquidbase xml files.
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'.
What am I doing wrong?
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 >
回答1:
Each included file needs to have the same XML root node as a standard changelog - so your 1.xml should look like this:
<?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 >
You may also need to specify in the master changelog that the included files are relative to the master changelog.
...
<include file="1.xml" relativeToChangelogFile="true"/>
...
Whether you need to do that is dependent on how you run liquibase.
回答2:
Refer to the post here - http://forum.liquibase.org/topic/declaration-not-found-databasechangelog . Changing the xsd version from 3.0 to 2.0 in xml file worked for me.
来源:https://stackoverflow.com/questions/23540464/liquibase-command-line-cannot-find-the-declaration-of-element-changeset