最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - Flyway failed migration is stuck in pending state - Stack Overflow

programmeradmin2浏览0评论

I have created a new flyway migration file and executed flywayMigrate:

ALTER TABLE xxx_user
    ADD creation_date TIMESTAMP WITHOUT TIME ZONE;

ALTER TABLE xxx_user
    ADD deleted BOOLEAN;

ALTER TABLE xxx_user
    ADD last_changed TIMESTAMP WITHOUT TIME ZONE;

ALTER TABLE xxx_user
    ALTER COLUMN deleted SET NOT NULL;

The migration failed with the message: ERROR: column “deleted” of relation “xxx_user” contains null values

I tried to fix the problem by adjusting the alter table command:

ALTER TABLE xxx_user
    ADD deleted BOOLEAN NOT NULL DEFAULT FALSE;

However, I cannot carry out this migration. FlywayMigrate gives the same error, which is supposed to be in an empty line. The status of the migration is pending and flywayRepair does not do anything, as there is no failed migration.

How can I solve this problem? Is there a way to delete or change pending migrations?

I have created a new flyway migration file and executed flywayMigrate:

ALTER TABLE xxx_user
    ADD creation_date TIMESTAMP WITHOUT TIME ZONE;

ALTER TABLE xxx_user
    ADD deleted BOOLEAN;

ALTER TABLE xxx_user
    ADD last_changed TIMESTAMP WITHOUT TIME ZONE;

ALTER TABLE xxx_user
    ALTER COLUMN deleted SET NOT NULL;

The migration failed with the message: ERROR: column “deleted” of relation “xxx_user” contains null values

I tried to fix the problem by adjusting the alter table command:

ALTER TABLE xxx_user
    ADD deleted BOOLEAN NOT NULL DEFAULT FALSE;

However, I cannot carry out this migration. FlywayMigrate gives the same error, which is supposed to be in an empty line. The status of the migration is pending and flywayRepair does not do anything, as there is no failed migration.

How can I solve this problem? Is there a way to delete or change pending migrations?

Share Improve this question edited Mar 28 at 9:56 MaAsche asked Mar 28 at 9:55 MaAscheMaAsche 53 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Unfortunately, flyway repair only fixes checksums and failed states in the flyway_schema_history table. It does not affect pending migrations or let you rerun modified scripts.

You have several options here:

Option 1: delete and recreate the migration file (best practice for pending)

Since the migration is still pending and not yet recorded in flyway_schema_history, you can safely delete or rename the file, create a corrected one, and run flyway migrate again.

Option 2: manually clean up the table (quick & risky)

If for some reason you're stuck and need to fix the pending state now, and you know it's safe to do so:

  • manually drop the partially added column

  • leave the migration file as-is (with corrected SQL) and rerun flyway migrate

Option 3: use flyway clean (destructive, dev only)

This will drop the entire database and reapply all migrations. Only use this in development environments!

发布评论

评论列表(0)

  1. 暂无评论