Skip to content
Latchkey

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.

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

.github/workflows/ci.yml
services:
  db:
    image: postgres:16   # empty DB each run
# step:
flyway migrate

Baseline a genuinely pre-existing schema

When adopting a real existing database, baseline once above the already-represented migrations.

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

How to prevent it

  • Use empty databases in CI so no baseline is needed.
  • Never drop flyway_schema_history on a managed database.
  • This is deterministic - retrying without baseline/clean DB fails identically.

Frequently asked questions

What causes ""non-empty schema(s) without baseline""?
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.
How do I fix "non-empty schema(s) without baseline"?
Start from an empty database so Flyway owns the full history from V1 and no baseline is needed.

Related guides

References

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