Liquibase“找不到元素‘databaseChangeLog’的声明";在 xml 更改日志文件中 [英] Liquibase "Cannot find the declaration of element 'databaseChangeLog'" in xml changeLog file

查看:26
本文介绍了Liquibase“找不到元素‘databaseChangeLog’的声明";在 xml 更改日志文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循来自 Liquibase 官方网站的 本指南,我创建了自己的changelog-master.xml

Following This guide from Liquibase's official website I've created my own 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 文件:

I've then created the liquibase.properties file in the same folder:

# 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 更改日志,它会正确运行并更新我的数据库.

Which is correct because if I run a normal .sql changelog it runs correctly and updates my DB.

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

I've then created a changelog file in sql which has to be automatically executed when launching liquibase update which is 000020-changelog.sql

--liquibase formatted sql

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

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

But when I go and launch liquibase update I get an error from the XML parser:

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

Unexpected error running Liquibase: cvc-elt.1.a: Cannot find the declaration of element 'databaseChangeLog'.

我不明白问题是什么.我已经多次检查 changelog-master.xml 文件是否正确并且看起来是正确的.从我可以找到的 cvc-elt.1.a 是一个 XML 解析错误,比如 databaseChangeLog 它没有在 xml 模式中声明.

And I can't understand what the problem is. I've checked multiple times if the changelog-master.xml file is correct and it looks like it is. And from what I can find the cvc-elt.1.a is an XML Parsing error, like databaseChangeLog it's not declared in the xml schema.

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

I'm doing this so that in the future I can create as many changelogs as I want and have them executed one after the other automatically.

我一直在为这个问题寻找一些解决方案,但我什么也找不到.我找到了一个官方论坛的链接,但它现在是一个死链接.

I've been looking for some solutions for this problem but I can't find anything. I've found a link to the official forums but it's now a dead link.

额外信息:

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

08/09/2020

08/09/2020 edit:

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

as asked in the comments this is the project's structure:

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 文件是必须运行以更新数据库的连续更改日志

testdb is the sqlite database I'm using to test liquibase. The .sql files are the consecutive changelogs that must be run to update the DB

推荐答案

导致我遇到问题的原因是我的 changelog-master.xml 中有一个过时的 XSD 版本,这导致某些东西闯入 XML 解析器.为了解决这个问题,我用以下内容对其进行了更改:

What was causing the issue I was having was the fact that in my changelog-master.xml I had an outdated XSD version, which was causing something to break into the XML Parser. To fix it I've changed it with the following:

<?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 格式的 sql 的文件将不会被执行.

and moved all my *.sql files into the schema/ folder. Other than that I've renamed all my .sql files using the *.databasetype.sql namescheme, in my case 000020-changelog.sqlite.sql. Had to do this because otherwise the files that used --liquibase formatted sql wouldn't be executed.

这篇关于Liquibase“找不到元素‘databaseChangeLog’的声明";在 xml 更改日志文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆