Flyway "Found non-empty schema(s) without baseline" in CI
Flyway found tables in the schema but no flyway_schema_history table to explain them. It will not assume which migrations already ran, so it stops and asks you to baseline the existing state. This is deterministic.
What this error means
flyway migrate fails on a database that already has objects but was never managed by Flyway, telling you to use baseline. It happens when pointing Flyway at a pre-existing database for the first time.
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
Pre-existing database adopted by Flyway
The schema was created some other way and Flyway is now run against it. Without a history table, Flyway cannot tell what has already been applied.
History table dropped or wrong schema targeted
The flyway_schema_history table was removed, or Flyway points at a schema that has objects but not its history table.
How to fix it
Use a clean database in CI
Start from an empty database so Flyway owns the full history from V1 and no baseline is needed.
services:
db:
image: postgres:16 # empty DB each run
# step:
flyway migrateBaseline a genuinely pre-existing schema
When adopting a real existing database, baseline once above the already-represented migrations.
flyway baseline -baselineVersion=1 -baselineDescription="existing schema"
flyway migrateHow to prevent it
- Use empty databases in CI so no baseline is needed.
- Never drop
flyway_schema_historyon a managed database. - This is deterministic - retrying without baseline/clean DB fails identically.