Skip to content
Latchkey

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.

flyway output
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.

Terminal
flyway baseline -baselineVersion=1 -baselineDescription="existing schema"
flyway migrate

Or use baselineOnMigrate for adoption

For an existing database, let migrate create the baseline automatically on first run.

Terminal
flyway migrate -baselineOnMigrate=true -baselineVersion=1

Use a clean database in CI instead

  1. For CI, start from an empty database so Flyway owns the full history from V1.
  2. Reserve baseline for adopting a genuinely pre-existing production schema.
  3. 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_history on a managed database.

Frequently asked questions

What causes ""non-empty schema(s) without schema history""?
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.
How do I fix "non-empty schema(s) without schema history"?
Mark the current state as a baseline version so Flyway only applies migrations newer than it.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card