Flyway "Found non-empty schema(s) without schema history table" in CI
Flyway found tables in the schema but no flyway_schema_history table, so it cannot tell what is already applied. To avoid stomping an existing database it stops and asks you to baseline.
What this error means
flyway migrate fails with "Found non-empty schema(s) public but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table."
ERROR: Found non-empty schema(s) "public" but no schema history table.
Use baseline() or set baselineOnMigrate to true to initialize the schema history table.Common causes
Migrating a pre-existing database with Flyway for the first time
The schema already has objects (created before Flyway, or by a seed step), but no history table exists, so Flyway will not assume what was applied.
A seed or restore step populated the schema before migrate
In CI a restore or fixture load created tables, then Flyway ran against the now non-empty schema.
How to fix it
Migrate against an empty database in CI
Run Flyway on a fresh service container so there is no pre-existing schema to conflict with.
services:
postgres:
image: postgres:16
env: { POSTGRES_PASSWORD: postgres }Baseline the existing schema
- If the schema legitimately predates Flyway, run
flyway baselineto create the history at a baseline version. - Or set
baselineOnMigrate=trueso the first migrate initializes the history table. - Then run
flyway migrateto apply versions above the baseline.
flyway -baselineOnMigrate=true migrateHow to prevent it
- Run CI migrations against a clean database with no pre-seeded tables.
- Baseline once when adopting Flyway on an existing database.
- Order steps so Flyway initializes the schema before any seed/restore.