Search code examples
postgresqlsqlalchemyceleryfastapialembic

fastapi alembic exclude celery tables


My postgres database already includes celery backend tables (celery_taskmeta and celery_tasksetmeta) and when i use the following command:

alembic revision --autogenerate -m "some message"

the generated file includes dropping these tables in upgrade section.

I have already tried the answer provided for this question but it's not working.


Solution

  • by adding celery's defined model base to target_metadata in alembic's env.py, alembic will recognize celery models as "not deleted".

    env.py:

    from celery.backends.database.session import ResultModelBase
    ...
    target_metadata = [Base.metadata, ResultModelBase.metadata]