#3896·flyway

Constants migrate flyway-maven-plugin 5.2.4 -> 6.x

Author: daggerokCreated May 23, 2024Updated Sep 23, 2026
Which version and edition of Flyway are you using?

Issue caused on anything is higher than 5.2.4

If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)

We are using java 8 / 11 so latest flyway maven plugin version that supports java 8 / 11 (9.22.3) is also failed

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Maven plugin

Which database are you using? (Type & version)

MySQL 8.4

Which operating system are you using?

macOS / Amazon Linux

What did you do? (Please include the content causing the issue, any relevant configuration settings, the SQL statement(s) that failed (if any), and the command you ran)

I have a lot of migrations already but used flyway maven plugin versions was too old and with a lot of vulnerabilities, so I've descided upgrade it to latests higher version which is supports java 8 and/or java 11

command I'm using is simple maven plugin goal

bash
mvn flyway:migrate

here is plugin config in pom.xml file:

xml
	<build>
		<plugins>
			<plugin>
				<groupId>org.flywaydb</groupId>
				<artifactId>flyway-maven-plugin</artifactId>
				<version>6.5.7</version>
				<configuration>
					<url>jdbc:mysql://localhost:3306/myappdb?serverTimezone=UTC</url>
					<baselineOnMigrate>true</baselineOnMigrate>
					<user>myappuser</user>
					<password>myapppassword</password>
					<table>schema_version</table>
					<cleanDisabled>true</cleanDisabled>
					<outOfOrder>true</outOfOrder>
				</configuration>
			</plugin>
		</plugins>
	</build>

here is content of db migration from line 66 where statement with issue is begin:

sql
INSERT INTO `role_privilege` (`role_id`, `privilege_id`)
VALUES
	(1,1),
	(3,1),
	(1,2),
	(3,2),
	(1,3),
	(3,3),
	(1,4),
	(3,4),
	(1,5),
	(3,5),
	(1,6),
	(3,6),
	(1,7),
	(3,7),
	(1,8),
	(3,8),
	(1,9),
	(3,9),
	(1,10),
	(3,10),
	(1,11),
	(1,12),
	(3,12),
	(1,13),
	(1,14),
	(1,15),
	(3,15),
	(1,16),
	(3,16),
	(1,17),
	(1,18),
	(3,18),
	(1,19),
	(3,19),
	(1,20),
	(3,20),
	(1,21),
	(3,21),
	(1,22),
	(3,22),
	(1,23),
	(3,23),
	(1,24),
	(3,24),
	(1,25),
	(3,25),
	(1,26),
	(3,26),
	(1,27),
	(3,27),
	(1,28),
	(3,28),
	(1,29),
	(3,29),
	(1,30),
	(3,30),
	(1,31),
	(1,32),
	(1,33),
	(1,34),
	(1,35),
	(1,36),
	(1,37),
	(2,37),
	(3,37),
	(1,38),
	(2,38),
	(3,38),
	(1,41),
	(1,42),
	(1,43),
	(1,44);
What did you expect to see?

some success results like it was with for example flyway-maven-plugin versions 3.1 or 5.2.4 before migration, something like that:

mvn flyway:migrate
# ...skipped
[INFO] Migrating schema `myappdb` to version 123456 - Previous migration
[INFO] Migrating schema `myappdb` to version 123457 - Add Role privilege
[INFO] Migrating schema `myappdb` to version 123458 - Next migration
# skipped...
[INFO] Successfully applied 190 migrations to schema `myappdb` (execution time 00:09.814s)
[WARNING] Flyway upgrade recommended: MySQL 8.4 is newer than this version of Flyway and support has not been tested.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.669 s
[INFO] Finished at: 2024-05-22T21:20:29-04:00
[INFO] ------------------------------------------------------------------------
What did you see instead?
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.5.7:migrate (default-cli) on project myproject: org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: 
[ERROR] Migration V234567__Add_Role_privilege.sql failed
[ERROR] --------------------------------------------------
[ERROR] SQL State  : 23000
[ERROR] Error Code : 1452
[ERROR] Message    : Cannot add or update a child row: a foreign key constraint fails (`myappdb`.`role_privilege`, CONSTRAINT `fk_role_privilege_role_id` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`))
[ERROR] Location   : /path/to/myproject/src/main/resources/db/migration/V1234567__Add_Role_privilege.sql (/path/to/myproject/src/main/resources/db/migration/V1234567__Add_Role_privilege.sql)
[ERROR] Line       : 66
[ERROR] Statement  : INSERT INTO `role_privilege` (`role_id`, `privilege_id`)
[ERROR] VALUES
[ERROR]         (1,1),
[ERROR]         (3,1),
[ERROR]         (1,2),
[ERROR]         (3,2),
[ERROR]         (1,3),
[ERROR]         (3,3),
[ERROR]         (1,4),
[ERROR]         (3,4),
[ERROR]         (1,5),
[ERROR]         (3,5),
[ERROR]         (1,6),
[ERROR]         (3,6),
[ERROR]         (1,7),
[ERROR]         (3,7),
[ERROR]         (1,8),
[ERROR]         (3,8),
[ERROR]         (1,9),
[ERROR]         (3,9),
[ERROR]         (1,10),
[ERROR]         (3,10),
[ERROR]         (1,11),
[ERROR]         (1,12),
[ERROR]         (3,12),
[ERROR]         (1,13),
[ERROR]         (1,14),
[ERROR]         (1,15),
[ERROR]         (3,15),
[ERROR]         (1,16),
[ERROR]         (3,16),
[ERROR]         (1,17),
[ERROR]         (1,18),
[ERROR]         (3,18),
[ERROR]         (1,19),
[ERROR]         (3,19),
[ERROR]         (1,20),
[ERROR]         (3,20),
[ERROR]         (1,21),
[ERROR]         (3,21),
[ERROR]         (1,22),
[ERROR]         (3,22),
[ERROR]         (1,23),
[ERROR]         (3,23),
[ERROR]         (1,24),
[ERROR]         (3,24),
[ERROR]         (1,25),
[ERROR]         (3,25),
[ERROR]         (1,26),
[ERROR]         (3,26),
[ERROR]         (1,27),
[ERROR]         (3,27),
[ERROR]         (1,28),
[ERROR]         (3,28),
[ERROR]         (1,29),
[ERROR]         (3,29),
[ERROR]         (1,30),
[ERROR]         (3,30),
[ERROR]         (1,31),
[ERROR]         (1,32),
[ERROR]         (1,33),
[ERROR]         (1,34),
[ERROR]         (1,35),
[ERROR]         (1,36),
[ERROR]         (1,37),
[ERROR]         (2,37),
[ERROR]         (3,37),
[ERROR]         (1,38),
[ERROR]         (2,38),
[ERROR]         (3,38),
[ERROR]         (1,41),
[ERROR]         (1,42),
[ERROR]         (1,43),
[ERROR]         (1,44)
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException