Search code examples
javaspring-data-jpaspring-datadatabase-migrationflyway

Flyway migration after jpa tables have been created


I'm using flyway database migration tool with a spring boot jpa project. When I run the server first flyway wants to migrate sqls, but tables have not created yet. In this case flyway returns an error which like

Caused by: org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateSqlException: Migration V1__countries_and_states.sql failed SQL State : 42S02 Error Code : 1146 Message : Table 'wallet.country' doesn't exist Location : db/migration/V1__countries_and_states.sql (/root/IdeaProjects/service/target/classes/db/migration/V1__countries_and_states.sql) Line : 1 I configured application.properties file with these options:

  • spring.flyway.baseline-on-migrate=true
  • spring.flyway.enabled=true
  • spring.flyway.clean-on-validation-error=true
  • spring.flyway.init-on-migrate=true

I want that my migration will have been successfully done.


Solution

  • Can be used configuration properties like: flyway.out-of-order = true. It says flyway works after hibernate/jpa has been created/updated tables.