0

I have a table definition inheriting from sqlalchemy's DeclarativeBase:

from sqlalchemy.orm import DeclarativeBase


class Base(DeclarativeBase):
    pass


class MyTable(Base):
    __tablename__ = "MyTable"
    __table_args__ = {"schema": "some_custom_schema"}

(some_custom_schema schema already exists in the empty database)

I'd like to create migration revision using alembic. I create the migration file by executing alembic revision --autogenerate which creates expected revision containing definitions to create the table. However, when I apply this migration to database and try to generate another migration, alembic spits out identical revision which tries to create the table all over again (which it shouldn't). For some reason this issue occurs only when I explicitly declare schema for the table other than default (public in case of postgresql). Using default schema produces expected outcome: first revision creates the table, second and later resembles only the changes that differ database from model definition. Why is the outcome of this operation different for custom schema and is there way to fix it?

Stan Reduta
  • 3,292
  • 5
  • 31
  • 55

0 Answers0