Flyway "Found non-empty schema(s) without schema history table"
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.
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 (manual SQL, another tool) and now Flyway is 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 is pointed at a schema that has objects but not the history table it expects.
How to fix it
Baseline the existing schema
Mark the current state as a baseline version so Flyway only applies migrations newer than it.
flyway baseline -baselineVersion=1 -baselineDescription="existing schema"
flyway migrateOr use baselineOnMigrate for adoption
For an existing database, let migrate create the baseline automatically on first run.
flyway migrate -baselineOnMigrate=true -baselineVersion=1Use a clean database in CI instead
- For CI, start from an empty database so Flyway owns the full history from V1.
- Reserve baseline for adopting a genuinely pre-existing production schema.
- Confirm Flyway targets the schema that actually holds (or should hold) the history table.
How to prevent it
- Let Flyway manage the schema from the start, or baseline once when adopting an existing one.
- Use empty databases in CI so no baseline is needed.
- Never drop
flyway_schema_historyon a managed database.