Daniel
Daniel

Reputation: 321

Liquibase "Cannot find the declaration of element 'databaseChangeLog'" in xml changeLog file

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>

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

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

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);

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

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

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.

Extra info:

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 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

Upvotes: 3

Views: 6602

Answers (2)

CH Liu
CH Liu

Reputation: 1884

For me, this issue is more related to http and https. The following shows the successful config:

<?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>

If http in any one of the three line is changed to https, it will throw the exception:

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'.

Upvotes: 5

Daniel
Daniel

Reputation: 321

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>

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.

Upvotes: 8

Related Questions