Skip to main content
Version: 6.14.0

Repairing failed Flyway migrations

The database migration scripts themselves should never generate an error, however there are external factors that can cause errors.

The steps to recover are dependent on the database vendor.

PostgreSQL​

All migrations are run in transactions so PostgreSQL will automatically roll back if it encounters an error. So simply fix the error and rerun the migration.

Oracle​

Oracle doesn't support transactional DDL so any changes are committed immediately.

In general there are 2 options for dealing with migration errors.

  1. Manually rollback, fix the issue and run migrate again
  2. Manually fix the issue, manually run the remaining migration statements and manually update the flyway status to mark the migration as successful.

Note: Depending on when the migration failed and the statements that it had already run, option 1 may not be possible.

Option 1

  • Run flyway repair to remove any failed migrations from the Flyway history
  • Undo any statements that were executed as part of the failed migration that executed before the failure
  • Fix the issue that caused the migration error
  • Run flyway migrate again to rerun the failed migration and the remaining migrations

Option 2

  • Fix the issue that caused the error

  • Manually run the remaining statements that are part of the failed Flyway migration

  • Update the Flyway status for the failed migration in the database: (assuming the migration failed in 2.3.11)

    update schema_version set success = 'TRUE' where version = '2.3.11'

Explanation​

  • UPDATE schema_version — specifies the table to update
  • SET success = 'TRUE' — sets the success column to the value 'TRUE'
  • WHERE version = '2.3.11' — limits the update to the row for migration version 2.3.11

Is 'TRUE' correct?

  • It depends on the database and the column type
  • PostgreSQL, Boolean column: Prefer TRUE without quotes
  • Integer column: Use 1 for success
  • Text column: 'TRUE' stores the string TRUE

For a standard Flyway schema_version table, the success column is typically an integer or boolean depending on the Flyway version and database schema. Check the actual column type before running the update.

If success is an integer column, use:

UPDATE schema_version SET success = 1 WHERE version = '2.3.11';
  • Run flyway migrate to run the remaining migrations