weixin_39890652
2020-12-04 13:24support PG INHERITS in autogenerate
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:
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
:
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('unicorn', 'name')
op.drop_column('unicorn', 'type_')
该提问来源于开源项目:sqlalchemy/alembic
- 点赞
- 回答
- 收藏
- 复制链接分享
4条回答
为你推荐
- 使用统一建模语言图对Go进行编程
- uml
- 4个回答
- 怎么画这个,纠结了一个星期了,求大神解答,最好有代码
- c#
- visual studio
- asp.net
- 2个回答
- asp.net做的登陆界面如何居中?
- visual studio
- asp.net
- 2个回答
- 中级壳类
- inheritance
- autoload
- php
- 1个回答
- PHP继承:如何从父级引用子对象?
- inheritance
- php
- 2个回答
换一换