You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Liquibase变更日志校验和不匹配问题求助(MySQL+Spring环境)

Liquibase Checksum Mismatch Error When Updating MySQL Schema

I'm learning to use Liquibase to update a MySQL database schema. I've created an empty schema in Workbench, and my Spring project configurations are as follows:

application.properties (under resources package)

spring.liquibase.enabled=true
spring.liquibase.change-log=classpath:db/changelog/changelog-master.yaml
spring.datasource.url=jdbc:mysql://localhost:3306/practice
spring.datasource.username=maxim
spring.datasource.password=123456
spring.jpa.hibernate.ddl-auto=update

I've confirmed the URL, username, password, and path to changelog-master.yaml are all correct.

changelog-master.yaml (under resources/db/changelog package)

databaseChangeLog:
  - include:
      file: changelog_1.yaml
      relativeToChangelogFile: true

changelog_1.yaml (under resources/db/changelog package)

databaseChangeLog:
  - changeSet:
      id: 1
      author: maxim
      changes:
        - createTable:
            tableName: Device
            columns:
              - column:
                  name: id
                  type: BIGINT
                  autoIncrement: true
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: name
                  type: VARCHAR
                  constraints:
                    nullable: false

When running the application, I hit this error:

liquibase.exception.ValidationFailedException: Validation Failed:1 change sets check sum classpath:db/changelog/changelog_1.yaml::1::maxim was: 8:8896ac0d055b8ae982733866bc5682b1 but is now: 8:1e0167b7454bbfa9b38e2c11740cadee

How can I resolve this issue?


Solutions

This error occurs because Liquibase stores a checksum of every executed changeSet in the databasechangelog table in your MySQL database. When it runs again, it compares the current changeSet's content against the stored checksum—if they don't match (either because you edited the changeSet, or there was a formatting change like whitespace), it throws this validation error. Here are practical fixes tailored to your development scenario:

1. Delete the conflicting changeSet record (development-only approach)

Since this is a learning project, the fastest fix is to remove the outdated checksum entry from the database:

  • Open MySQL Workbench and connect to your practice database.
  • Run this SQL query:
    DELETE FROM databasechangelog WHERE ID = '1' AND AUTHOR = 'maxim';
    
  • Restart your Spring app. Liquibase will re-run the changeSet and save the new, correct checksum.

2. Add a validCheckSum to the changeSet

If you intentionally modified the changeSet and want Liquibase to accept the new checksum, add the validCheckSum attribute directly to your changeSet in changelog_1.yaml:

databaseChangeLog:
  - changeSet:
      id: 1
      author: maxim
      validCheckSum: 8:1e0167b7454bbfa9b38e2c11740cadee # Use the new checksum from your error message
      changes:
        - createTable:
            tableName: Device
            columns:
              - column:
                  name: id
                  type: BIGINT
                  autoIncrement: true
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: name
                  type: VARCHAR
                  constraints:
                    nullable: false

This tells Liquibase the new checksum is valid, so it won't flag a mismatch.

3. Clear all checksums via Liquibase CLI

If you have the Liquibase CLI set up, run this command to wipe all stored checksums—Liquibase will recalculate them on the next application start:

liquibase clearCheckSums

Ensure your liquibase.properties file has the correct database connection details before executing this.

A quick note on your Hibernate config

Since you're using Liquibase to manage schema changes, it's best to set spring.jpa.hibernate.ddl-auto=none in your application.properties. This prevents Hibernate's automatic schema updates from conflicting with Liquibase's managed changeSets.


内容的提问来源于stack exchange,提问作者user13353974

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:26:47