Error and exception examples

This section contains some error and exception examples that may help you with troubleshooting Flyway.

Violation of PRIMARY KEY constraint

From the log:


SQL State  : null
Error Code : 0
Message    : java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: 
Violation of PRIMARY KEY constraint 'PK_WKBR_REGISTRY'. Cannot insert duplicate key in 
object 'dbo.WORKBRAIN_REGISTRY'. The duplicate key value is (2470).
Location   : db/migrations/data/modules/ta/QuickRules/20180213200235719__
WTA-200_Add_Has_Insufficient_Rest_Condition.wbsqld (D:\Infor\flyway-7.0.0.11\db\migrations\data
\modules\ta\QuickRules\20180213200235719__WTA-200_Add_Has_Insufficient_Rest_Condition.wbsqld)
Line       : 1
Statement  : INSERT INTO WORKBRAIN_REGISTRY (WBREG_ID,WBREG_PARENT_ID,WBREG_NAME,WBREG_CLASS,
WBREG_ALT_PARENT_ID,WBREG_ORDINAL)
VALUES (2470, 87,'com.workbrain.app.ta.conditions.HasInsufficientRestCondition', 
'java.lang.String', -1, -1)

at com.workbrain.flyway.custom.migrations.WBSQLDataMigrationImpl2.execute(WBSQLDataMigrationImpl2.java:92)
at com.workbrain.flyway.custom.migrations.WBSQLMigrationImpl.migrate(WBSQLMigrationImpl.java:69)
 at com.workbrain.flyway.custom.executors.WBSQLExecutor.execute(WBSQLExecutor.java:44)
        ... 20 more
Caused by: java.sql.SQLException: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerException: 
Violation of PRIMARY KEY constraint 'PK_WKBR_REGISTRY'. Cannot insert duplicate key in object 
'dbo.WORKBRAIN_REGISTRY'. The duplicate key value is (2470).
        ... 23 more

This error indicates that Flyway is trying to insert an entry with a primary key already contained in the database

To resolve this issue:

  1. Open the failing migration and locate the SQL statement causing the issue.
  2. Understand why the entry why the key already exists in the database, the upgrade is making an assumption that the entry should not be there, having it in indicates a potential problem either with the data or with the migration.
  3. In order for migrations to proceed the offending data needs to be removed first. If the data is still required post migration it needs to be saved.
  4. Rerun Flyway.
  5. If necessary, restore the data that was removed using appropriate update statements.

Detected resolved migration not applied to database

From the log:


[java] Exception in thread "main" org.flywaydb.core.api.FlywayException: org.flywaydb.core.api.FlywayException: 
Validate failed: Detected resolved migration not applied to database: 20190930164328870
     [java]     at com.workbrain.flyway.WBFlyway.main(WBFlyway.java:219)
     [java] Caused by: org.flywaydb.core.api.FlywayException: Validate failed: Detected resolved migration not 
applied to database: 20190930164328870
     [java]     at org.flywaydb.core.Flyway.doValidate(Flyway.java:1024)
     [java]     at org.flywaydb.core.Flyway.access$100(Flyway.java:72)

This error indicates that Flyway is seeing a migration that should have already been executed. The sequence number of this migration is lower than the sequence number of the last migration executed during previous Flyway run. This is a normal situation when doing an upgrade from a maintenance version.

To ignore this error:

  1. If you want Flyway to ignore this error, set migration.outOfOrder to true. This setting is already set to true in most example configuration files provided with WFM.

Migration checksum mismatch

From the log:


[java] Exception in thread "main" org.flywaydb.core.api.FlywayException: org.flywaydb.core.api.FlywayException: 
Validate failed: Migration checksum mismatch for migration 20190930164328870
     [java] -> Applied to database : 1693908478
     [java] -> Resolved locally    : 2134882121
     [java]     at com.workbrain.flyway.WBFlyway.main(WBFlyway.java:219)

This error indicates that a migration applied during the previous execution of Flyway was modified and is available to the current execution of Flyway only in the new form. This condition can happen if the rule mentioned above of not changing migrations was violated.

To resolve this issue:

  1. If a migration was manually changed prior to running Flyway undo these changes and rerun Flyway.
  2. If files were probably not changed, identify who had previously executed Flyway and discover what was done to the mentioned migrations. This situation will require working with the group who made the initial change or with Infor Support to recover.