Skip to content

Stamp command with "base" emits a DROP if --sql mode is present and no head revisions are present #1822

Description

@Jazzinghen

Describe the bug
I tried executing the stamp command by passing "base" as the target revision. Instead of deleting the table Alembic confirms the existence of the alembic_version table and then returns.

What is even more strange is that when calling the command using the --sql function you get the expected behavior:

$ alembic stamp --sql base
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Generating static SQL
INFO  [alembic.runtime.migration] Will assume transactional DDL.
BEGIN;

DROP TABLE alembic_version;

COMMIT;

Expected behavior
Alembic should delete the alembic_version even if there are no migrations, as it creates the table if there are no migrations.

To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.

  1. Start a Postgresql server: docker run --name some-postgres -p 54321:5432 -e POSTGRES_PASSWORD=letmein postgres:18
  2. Initialize Alembic in a folder: alembic init
  3. Edit the configuration to point at the database: sqlalchemy.url = postgresql://postgres:letmein@localhost:54321/postgres
  4. Stamp the database: alembic stamp head
  5. Check the status of the table in the database: select * from alembic_version;. This should return an empty table
  6. Clear the database: alembic stamp base
  7. The command from step 6 will still return an empty table instead of erroring out because the table doesn't exist anymore.

Versions.

  • OS: Linux 7.0.12-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 10 Jun 2026 08:58:02 +0000 x86_64 GNU/Linux
  • Python: 3.14.5
  • Alembic: 1.18.4
  • SQLAlchemy: 2.0.51
  • Database: Postgresql 18.4
  • DBAPI: Psycopg 3.3.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions