How to fix ValidationFailedException in liquibase checksum?

I am using liquibase with spring boot. I am having SQL changesets. I have not changed anything in the liquibase SQL scripts. but I am getting below error

Error creating bean with name ‘liquibase’ defined in class path
resource: Invocation of init method failed; nested exception is
liquibase.exception.ValidationFailedException: Validation Failed:\r\n
1 change sets check sum\r\n
liquibase/db/0001_sample.sql::sample1_2::admin was:
8:600cf084d9c1ea85df2ddaa4f7a8a309 but is now:
8:47d241e6e1636203501ec72cafe4e5b6\r\n",
“class”: “org.springframework.beans.factory.BeanCreationException”,

Below is my 0001_table1.sql

--liquibase formatted sql
--changeset admin:sample1_1
create table....
--rollback DROP TABLE tablename

--changeset admin:sample1_2
add column....

I think this is due to formatting changing from my IDE to another ide. But I like to fix it. I am not looking for clearing checksum. Please suggest how to handle when using plain SQL with liquibase.

Note: I have seen examples with xml version, but I am looking for SQL with liquibase.

Could you use a SQL UPDATE statement to change it in DATABASECHANGELOG?

You should break your change sets up. Don’t use a single file since when you add to it, the hash will change.

Here’s how we have ours set up:

changelog.xml:

<?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"
	xmlns:pro="http://www.liquibase.org/xml/ns/pro"
	xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
		http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd
		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.9.xsd">

    <includeAll path="schema/"/>
</databaseChangeLog>

and then we use the schema/ folder to keep them organized. Don’t mind the xml suffixes, you can use sql files if you like. They are done in sequential order:

ekolp@KRSDEVEKOLPMBP13 liquibase % ls -lash schema 
total 16
0 drwxr-xr-x   4 ekolp  staff   128B Apr 19 16:53 .
0 drwxr-xr-x  16 ekolp  staff   512B Apr 19 16:53 ..
8 -rw-r--r--   1 ekolp  staff   1.3K Apr 19 16:53 221.xml
8 -rw-r--r--   1 ekolp  staff   1.9K Apr 18 11:02 222.xml

then a run looks like this:

Schema change running for elk on Mon Apr 18 21:30:56 UTC 2022
[2022-04-18 21:31:03] INFO [liquibase.integration] No Liquibase Pro license key supplied. Please set liquibaseProLicenseKey on command line or in liquibase.properties to use Liquibase Pro features.
Liquibase Community 4.3.4 by Datical
####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ## 
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ## 
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 21:31:03 (version 4.3.4 #55 built at 2021-04-19 20:18+0000)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
[2022-04-18 21:31:06] INFO [liquibase.lockservice] Successfully acquired change log lock
[2022-04-18 21:31:07] INFO [liquibase.changelog] Reading resource: schema/221.xml
[2022-04-18 21:31:08] INFO [liquibase.changelog] Reading resource: schema/222.xml
[2022-04-18 21:31:08] INFO [liquibase.changelog] Reading from elk.DATABASECHANGELOG
[2022-04-18 21:31:09] INFO [liquibase.ext] Using percona toolkit: 3.3.0
[2022-04-18 21:31:09] INFO [liquibase.lockservice] Successfully released change log lock
[2022-04-18 21:31:09] INFO [liquibase.lockservice] Successfully acquired change log lock
Skipping auto-registration
[2022-04-18 21:31:09] WARNING [liquibase.hub] Skipping auto-registration
[2022-04-18 21:31:09] INFO [liquibase.changelog] Index ProductCodeText dropped from table linesum
[2022-04-18 21:31:09] INFO [liquibase.changelog] ChangeSet schema/221.xml::221-2::ekolp ran successfully in 66ms
[2022-04-18 21:31:09] INFO [liquibase.changelog] Columns created_at(DATETIME) added to member_custom_fields
[2022-04-18 21:31:09] INFO [liquibase.changelog] ChangeSet schema/222.xml::222-1::ekolp ran successfully in 95ms
[2022-04-18 21:31:09] INFO [liquibase.changelog] Columns updated_at(TIMESTAMP) added to member_custom_fields
[2022-04-18 21:31:09] INFO [liquibase.changelog] ChangeSet schema/222.xml::222-2::ekolp ran successfully in 73ms
[2022-04-18 21:31:09] INFO [liquibase.lockservice] Successfully released change log lock
Liquibase: Update has been successful.

I may have misread the original post. I will leave my posts up in case they are needed.

I am getting below error without any changes in the sql file.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘liquibase’ defined in class path resource [//LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.ValidationFailedException: Validation Failed:\n 1 change sets check sum\n liquibase/db/0003_batch.xml::batch_1::admin was: 8:9c49637ad724b7ded237f91f8a567d0b but is now: 8:93aef70e06bda354629b39e6607fd363

I have seen it happen, not sure why. You have a few options:

  1. run a “clear-checksums” command followed by and “update” command. This will clear all md5sums and recalculate them during the update, which will prevent the error.
  2. Add --validCheckSum to your changeset with the new value. (see: Example Changelogs: SQL Format | Liquibase Docs)
  3. Update the databasechangelog table, setting the md5sum to NULL for the particular row. This will do basically the same as #1.

Daryl,

Do we need to run clear-checksums everytime we are adding another sql ddl/dml to same file?
My changeset file::
–liquibase formatted sql

–changeset renuka:20190221092200

CREATE TABLE [dbo].[CustomerDetails](
[CustomerTypeID] nchar NULL,
[CustomerDesc] nvarchar NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

–changeset renuka:20221010101010

Create Table dbo.t1(id int,
name char(15))

Error:: Unexpected error running Liquibase: Validation Failed:
1 changesets check sum

No, clear-checksums is only for very specific scenarios. You want Liquibase to use the MD5SUM stored in the databasechangelog to determine if a changeset has been modified.

If you are getting the checksum error it indicates you have modified a changeset that Liquibase has already executed, which is an unexpected condition.