Skip to content
Latchkey

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

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

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.

.github/workflows/ci.yml
services:
  postgres:
    image: postgres:16
    env: { POSTGRES_PASSWORD: postgres }

Baseline the existing schema

  1. If the schema legitimately predates Flyway, run flyway baseline to create the history at a baseline version.
  2. Or set baselineOnMigrate=true so the first migrate initializes the history table.
  3. Then run flyway migrate to apply versions above the baseline.
Terminal
flyway -baselineOnMigrate=true migrate

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

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →