【问题标题】:Liquibase "Cannot find the declaration of element 'databaseChangeLog'" in xml changeLog fileLiquibase“在xml changeLog文件中找不到元素'databaseChangeLog'的声明”
【发布时间】:2020-09-04 13:17:03
【问题描述】:

根据 Liquibase 官方网站上的This guide,我创建了自己的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' information  ####
url=jdbc:sqlite://home/username/liquibase/examples/sqlite-test/testdb

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

然后我在 sql 中创建了一个更改日志文件,该文件必须在启动 liquibase update 时自动执行,即 000020-changelog.sql

--liquibase formatted sql

--changeset daniel:3
create table phonebook(name TEXT, surname TEXT, type TEXT, phone_number TEXT);

但是当我启动 liquibase update 时,我从 XML 解析器中得到一个错误:

运行 Liquibase 时出现意外错误:cvc-elt.1.a:找不到元素“databaseChangeLog”的声明。

而且我不明白问题出在哪里。我已经多次检查changelog-master.xml 文件是否正确并且看起来是正确的。从我可以找到的cvc-elt.1.a 是一个XML 解析错误,就像databaseChangeLog 它没有在xml 架构中声明。

我这样做是为了在将来我可以创建任意数量的变更日志,并让它们一个接一个地自动执行。

我一直在为这个问题寻找一些解决方案,但我找不到任何东西。我找到了官方论坛的链接,但现在是死链接。

额外信息:

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

2020 年 8 月 9 日编辑:

根据 cmets 的要求,这是项目的结构:

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

testdb 是我用来测试 liquibase 的 sqlite 数据库。 .sql 文件是更新数据库必须运行的连续更改日志

【问题讨论】:

  • 您能否也包括项目结构,即更改日志主文件的路径是否正确设置?
  • 嗨@sudo 我刚刚用项目结构更新了帖子

标签: xml-parsing liquibase


【解决方案1】:

导致我遇到问题的原因是,在我的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/ 文件夹中。除此之外,我使用*.databasetype.sql 命名方案重命名了我所有的.sql 文件,在我的情况下为000020-changelog.sqlite.sql。必须这样做,否则使用 --liquibase formatted sql 的文件将不会被执行。

【讨论】:

  • 这也解决了我的问题。我不得不从使用 liquibase 示例中显示的“databaseChangeLog”节点切换到此答案中的节点
【解决方案2】:

对我来说,这个问题与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'.

【讨论】:

  • 谢谢。
猜你喜欢
  • 2012-07-02
  • 1970-01-01
  • 2015-07-04
  • 1970-01-01
  • 2020-10-12
  • 2021-09-07
  • 1970-01-01
  • 2019-02-25
  • 1970-01-01
相关资源
最近更新 更多