[Solved] Flyway Error: Detected applied migration not resolved locally:2 and the execution script error

I preface

Flyway is used in actual development. Let’s briefly introduce flyway

1. Flyway introduction

Flyway is an open source database version management tool. It can be easily used in the command line or introduced in Java applications to manage our database version.

In a project or product, it is difficult to clarify the business at the beginning and design the database table well, so the data table will also iterate continuously in the iteration cycle. Using flyway in Java applications can be used to iterate the database table structure quickly and effectively, and ensure that the data tables are consistent when deployed to the test environment or production environment.

Please refer to flyway’s official documents for details


2. Flyway dependency package


3. Benefits of using flyway

In multi person development projects, we are used to using SVN or git to version control the code. The main purpose is to solve the problems of code conflict and version fallback in multi person development.

II Problem analysis

1. Flyway reports an error: detected applied migration not resolved locally:2

When using flyway for system management, my program reported such errors

1.1 problem analysis:

Reported error: Application migration not detected locally resolved

The reason for this problem is:

1. because the imported database contains flyway_schema_history table, so the local runtime version inconsistent error,

2. I migrated a version 2 sql, then I deleted it, and when I ran it again for the second time, I couldn’t find the V2__orange_cms file that I migrated before.

1.2 Solution
Special Note: Must be in test environment and local environment

1. mvn flyway:clean, this step will clear the existing data.

2. Ensure that the configuration file is open for flyway.

3. Start the project, complete the initialization of the flyway_schema_history table, backup the flyway_schema_history table after the startup is complete

4. Import the data, at this time the flyway_schema_history table will be updated to the version of the imported data

5. After the successful import, delete the flyway_schema_history table and replace it with the backup flyway_schema_history table

6. Start the application again, Success!


2. Script execution error

2.1 problem analysis

The general meaning of the error message: when flyway is opened in my project configuration file, it will explode: the execution of SQL is abnormal, and the “XXX” table cannot be found

This is a problem that has bothered me for a long time. I don’t know where my program and configuration are wrong

Error reason: because our flyway is based on the version of database mysql5.7, but my local database version is mysql5.5, the error “cannot find XXX table” is always reported when starting flyway configuration for database initialization

2.2 problem solving

Upgrade our database version, which is greater than or equal to our development database version. Due to the twists and turns in the road of upgrading the database, we suggest that you learn from it: more detailed


Open our flyway configuration after the database upgrade

Start the program to see if our project can start successfully


Read More: