70

Maven fires liquibase validation fail even no changes was made in changeset.

My database is oracle.

Situation:

  1. In DB changelog table was record for changeset <changeSet id="1" author="me" dbms="oracle">;

  2. Then by mistake i added another changeset <changeSet id="1" author="me" dbms="hsqldb">

  3. Reruned liquibase scripts Maven fired checksum validation error.

  4. Then i changed hsqldb changeSet to <changeSet id="2" author="me" dbms="hsqldb">

  5. Maven still firing checksum validation error.

  6. Then i changed first changeSet checksum in DB manually to current checkSum and scripts runned successfully.

Everything looks nice ,but when i redeploy whole application and run liquibase scripts checksum of first changeSet is still like before 6 step.

Daggeto
  • 943
  • 1
  • 8
  • 17

9 Answers9

93

If you're confident that your scripts correctly reflect what should be in the database, run the liquibase:clearCheckSums maven goal, which will clean it all up.

Taoufik Mohdit
  • 1,910
  • 3
  • 26
  • 39
Roy Truelove
  • 22,016
  • 18
  • 111
  • 153
  • 2
    [ERROR] Could not find goal 'clearCheckSums' in plugin org.liquibase:liquibase-plugin:1.9.6 :-( – Patrick Cornelissen Jun 05 '13 at 11:26
  • 1
    @PatrickCornelissen Looking at the link below it seems that the plugin version you're using is quite old - there's probably a newer version under a different name? http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.liquibase%22%20AND%20a%3A%22liquibase-plugin%22 – Roy Truelove Jun 05 '13 at 13:09
  • 4
    For gradle it's `./gradlew liquibaseClearChecksums` – agilob May 15 '18 at 08:30
  • mvn liquibase:clearCheckSums ##execute in your project folder – Allahbakash.G Nov 01 '18 at 10:10
  • I tried this and indeed it will successfully run the LB script but it doesn't reflect my changes on database. What I did was delete the problematic databasechangelog. – Camilo Go Jr. Sep 09 '21 at 10:15
  • I'm not sure I understand exactly what you mean by "scripts correctly reflect what should be in the database", and nor am I sure I understand what the `liquibase:clearCheckSums` maven goal actually does. Will it delete any data? If I had 2 change sets, and the second one is bugged, what happens to the database when I run that command? – payne Oct 22 '21 at 21:57
19

In my case I forgot that Liquibase writes all changelogs to database table.

Go to DATABASECHANGELOG table and remove manually your changelogs.

18

Everyone here is talking about how to fix this, but let me share a typical scenario where it may occur for you.

SHORT ANSWER : Change in line-separator due to one reason or another can cause checksum validation error and won't be visible in code changes.

Why did it occur for me? Please read below..

Suppose you have a tomcat server, and multiple people are involved in WAR deployment from time to time. Everyone uses INTELLIJ IDEA on LINUX but one of the team member switches to WINDOWS for some reason. Now, when the WINDOWS PERSON would create WAR, he may not notice that default line-separator selection in INTELLIJ IDEA for WINDOWS is CRLF but all previous builds built from LINUX machine which uses LF line-separator.

Change in line-separator affects all text files, which includes SQL files too. So you may have used following just like my team in your liquibase script

changeSet(author: "aditya", id: "1335831637231-1") {
    sqlFile( path: "liquibase/quartz_oracle_tables.sql", "stripComments": true)
}

and the checksum of file would not match the one already stored in database throwing checksum validation error.

Aditya T
  • 1,566
  • 2
  • 13
  • 26
  • 2
    Would be worth adding this as a separate question - the original question was "I change my files, then Liquibase fails, why?" whereas this is "I didn't change my files, but Liquibase *still* fails, why???!" – Andrew Spencer Jan 24 '19 at 07:41
  • I am not sure if we are allowed to that, but yes it can help people better in the same scenario I faced. – Aditya T Jan 24 '19 at 13:30
  • This answer was helpful from my perspective. Note, it comes up as first result for searching "liquidbase validation failed checksum" – Thomas Carlisle Jun 20 '21 at 17:11
  • It occurs when you are modifying the already executed changeset. – Touchstone Jul 22 '22 at 14:00
15

Liquibase reads databasechangelog table to validate recent changes. So identify the databasechangelog id which is causing the problem and delete, as shown below:

select * from myschema.DATABASECHANGELOG;

Delete from myschema.DATABASECHANGELOG where ID='prob_id';

Deleting a bad changelog in Liquibase

Nandan
  • 497
  • 2
  • 7
  • 18
6

As I struggle with this one I want to make it easier for people with this same issue:

  1. Important!, liquibase has a liquibase has a changlog.xml file
  2. On the maven pom.xml place the following properties.

<project ...>
  <plugins>
    <plugin>
      <groupId>org.liquibase</groupId>
      <artifactId>liquibase-maven-plugin</artifactId>
      <version>*****</version>
      <configuration>
        <changeLogFile>src/main/resources/mychangelogfile.xml</changeLogFile>
        <driver>oracle.jdbc.driver.OracleDriver</driver>
        <url>jdbc:oracle:thin:@//X.X.X.X:PORT/XE</url>
        <username>yourusername</username>
        <password>password</password>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>clearCheckSums</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</project>

**** version the one I used 3.2.0 in url replace with proper IPADDRESS and PORT.

Finally you run mvn liquibase:clearCheckSums

Hope it helps!

acabra85
  • 369
  • 4
  • 13
4

The liquibase documentation has a 2nd option now

The <validCheckSum> attribute

The second option is to add a <validCheckSum> element to the changeset. The text contents of the element should contain the old checksum from the error message.

Assuming you rarely have to change historic changelog XML files, then you rarely have error messages. If you get an error message then add a tag with the old checksum acknowledging it's fine.

Example:

    <changeSet id="example" author="former-author" runOnChange="false">
       <validCheckSum>8:869....4e3</validCheckSum>
       <addColumn tableName="ye_olde_db_table">
          <!-- fix some old typo or incompatibility, etc -->
       </addColumn>
    </changeSet>
Steve Jones
  • 1,528
  • 19
  • 12
0

Configure liquibase's database link information in the maven plugin.

like this:

<plugin>
  <groupId>org.liquibase</groupId>
  <artifactId>liquibase-maven-plugin</artifactId>
  <version>${liquibase.version}</version>
  <configuration>
    <changeLogFile>${project.basedir}/src/main/resources/config/liquibase/master.xml</changeLogFile>
    <driver>com.mysql.cj.jdbc.Driver</driver>
    <url>jdbc:mysql://localhost:3306/hos_gateway</url>
    <username>root</username>
    <password>root</password>
    <referenceUrl>hibernate:spring:com.hos.physician.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&amp;hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
    <verbose>true</verbose>
    <logging>debug</logging>
    <contexts>!test</contexts>
  </configuration>
</plugin>
zmag
  • 7,825
  • 12
  • 32
  • 42
GuoGuang
  • 41
  • 6
0

Changeset id should not repeat. Give a new changeset id and try, it should work.

<changeSet id=
0

In my case, changelog.yml file had incorrect id.

databaseChangeLog:

  • changeSet: id: 1.0.xx
Smart Coder
  • 1,435
  • 19
  • 19