support PG INHERITS in autogenerate

Issue #404 new
Quentin Leffray
created an issue

Running Alembic autogenerate do not detect inherited columns from a parent table, and flag them as "to-be-dropped".

The model is defined as follow:

class Animal(Base):
    __tablename__ = 'animal'

    id = Column(Integer, primary_key=True)
    name = Column(String)
    type_ = Column(String)

    __mapper_args__ = {
        'polymorphic_identity': 'animal',
        'polymorphic_on': type_,
        'with_polymorphic': '*',

class Unicorn(Animal):
    __tablename__ = 'unicorn'
    __table_args__ = {'postgresql_inherits': 'animal'}

    id = Column(Integer, ForeignKey(''), primary_key=True)
    color = Column(String)

    __mapper_args__ = {
        'polymorphic_identity': 'unicorn',

And the migration produced by alembic --autogenerate:

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('unicorn', 'name')
    op.drop_column('unicorn', 'type_')

Comments (2)

  1. Michael Bayer repo owner

    nothing is wrong, this is something that isn't supported out of the box. At the very least would rely upon For autogenerate you need to write an include_object routine to ignore these columns appropriately. I'd also accept a recipe section that includes this workaround for now.

  2. Log in to comment