xml changeLog文件中的Liquibase“找不到元素'databaseChangeLog'的声明”

问题描述

This guide之后,我在Liquibase的官方网站上创建了自己的changelog-master.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="https://www.liquibase.org/xml/ns/dbchangelog"
               xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="https://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
    <includeAll path="/home/username/liquibase/examples/sqlite-test" filter="sql"/>
</databaseChangeLog>

然后我在同一文件夹中创建了liquibase.properties文件

# Enter the path for your changelog file.
changeLogFile=changelog-master.xml

#### Enter the Target database 'url' @R_128_4045@ion  ####
url=jdbc:sqlite://home/username/liquibase/examples/sqlite-test/testdb

这是正确的,因为如果我运行普通的.sql更改日志,它将正确运行并更新我的数据库

然后我在sql中创建了一个变更日志文件,该文件必须在启动liquibase update的{​​{1}}时自动执行。

000020-changelog.sql

但是当我启动--liquibase formatted sql --changeset daniel:3 create table phonebook(name TEXT,surname TEXT,type TEXT,phone_number TEXT); 时,我从XML解析器中得到了一个错误

运行Liquibase时发生意外错误:cvc-elt.1.a:找不到元素'databaseChangeLog'的声明。

我不明白问题是什么。我已经多次检查liquibase update文件是否正确,看起来是否正确。从我发现changelog-master.xml一个XML解析错误,就像cvc-elt.1.a一样,它没有在xml模式中声明。

我正在这样做,以便将来我可以根据需要创建尽可能多的变更日志,并使它们自动一个一个地执行。

我一直在寻找一些解决此问题的方法,但找不到任何东西。我已经找到了官方论坛的链接,但现在它已失效。

其他信息:

  • Liquibase版本4.0.0
  • 已安装的JRE:openjdk 11.0.8 2020-07-14
  • 操作系统:Debian 10
  • sqlite 3.27.2版

2020年9月9日修改

评论中所述,这是项目的结构:

databaseChangeLog

root@dev-machine:/home/username/liquibase/examples/sqlite-test# ls -la total 68 drwxr-xr-x 2 root root 4096 Sep 4 17:28 . drwxr-xr-x 5 username username 4096 Sep 4 17:02 .. -rw-r--r-- 1 root root 139 Sep 4 13:35 000020-changelog.sql -rw-r--r-- 1 root root 118 Sep 4 13:36 000030-changelog.sql -rw-r--r-- 1 root root 201 Sep 4 17:05 000040-changelog.sql -rw-r--r-- 1 root root 240 Sep 4 17:28 000050-changelog.sql -rw-r--r-- 1 root root 456 Sep 4 14:22 changelog-master.xml -rw-r--r-- 1 root root 2637 Sep 4 16:36 liquibase.properties -rw-r--r-- 1 root root 32768 Sep 4 17:28 testdb 是我用来测试liquibase的sqlite数据库testdb文件是必须运行以更新数据库的连续变更日志

解决方法

导致我遇到问题的原因是,在我的changelog-master.xml中,我有一个过时的XSD版本,这导致某些东西被XML解析器破坏。要修复它,我已使用以下内容对其进行了更改:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog 
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog" 
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" 
    xmlns:pro="http://www.liquibase.org/xml/ns/pro" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext 
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd 
    http://www.liquibase.org/xml/ns/pro 
    http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.0.xsd 
    http://www.liquibase.org/xml/ns/dbchangelog 
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
    ">
    <includeAll path="schema/"/>
</databaseChangeLog>

,然后将我所有的* .sql文件移动到schema/文件夹中。除此之外,我还使用.sql名称方案(在我的情况下为*.databasetype.sql)重命名了所有000020-changelog.sqlite.sql文件。之所以这样做,是因为否则将不会执行使用--liquibase formatted sql的文件。

,

对我来说,这个问题与 httphttps 更相关。下图显示了成功的配置:

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"                 <-- NOT HTTPS!
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               <-- NOT HTTPS!
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog     <-- NOT HTTPS!
  https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
  <includeAll path="changelogs/" relativeToChangelogFile="true"/>
</databaseChangeLog>

如果将三行中任何一行的http改为https,都会抛出异常:

liquibase.exception.ChangeLogParseException: Error parsing line 6 column 70
of classpath:db/main.xml: cvc-elt.1.a: Cannot find the declaration of
element 'databaseChangeLog'.