Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support PG INHERITS in autogenerate #404

Open
sqlalchemy-bot opened this issue Dec 22, 2016 · 3 comments
Open

support PG INHERITS in autogenerate #404

sqlalchemy-bot opened this issue Dec 22, 2016 · 3 comments

Comments

@sqlalchemy-bot
Copy link
Owner

Migrated issue, originally created by Quentin Leffray ()

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:

#!python
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('animal.id'), primary_key=True)
    color = Column(String)

    __mapper_args__ = {
        'polymorphic_identity': 'unicorn',
    }

And the migration produced by alembic --autogenerate:

#!python

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('unicorn', 'name')
    op.drop_column('unicorn', 'type_')
@sqlalchemy-bot
Copy link
Owner Author

Changes by Quentin Leffray ():

  • edited description

@sqlalchemy-bot
Copy link
Owner Author

Michael Bayer (zzzeek) wrote:

nothing is wrong, this is something that isn't supported out of the box. At the very least would rely upon https://bitbucket.org/zzzeek/sqlalchemy/issues/1803/reflect-postgresql-inherits-relationships. 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.

@sqlalchemy-bot
Copy link
Owner Author

Changes by Michael Bayer (zzzeek):

  • removed labels: bug
  • added labels: feature
  • changed title from "Autogenerate detection of inherited columns and po" to "support PG INHERITS in autogenerate"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant