Controlling what Alembic Autogenerates

Alembic can autogenerate migrations. This is probably its most valuable feature. However, I had a situation where --autogenerate kept on creating migrations for the databasechangelog and databasechangeloglock tables. These are Liquibase tables and should never feature in the Alembic migrations.

The solution was to tell Alembic to ignore these tables by updating the module.

First create a function that will detect the offending tables.

def include_object(object, name, type_, reflected, compare_to):
    # Don't include these tables. Add other tables to list as required.
    return name not in ["databasechangelog", "databasechangeloglock"]

Now pass this function as a callback when configuring the Alembic context.