Alembic Migration:如何删除多态身份

时间:2015-11-10 22:42:52

标签: sqlalchemy alembic

我有以下设置

class Content(Base):
    """Content object"""
    __tablename__ = "content"
    id = Column(Integer, primary_key=True)
    name = Column(Unicode(255),unique=True, nullable=False)
    title = Column(Unicode(255))
    body = Column(UnicodeText)
    created = Column(DateTime, default=func.now())
    modified = Column(DateTime, onupdate=func.now())
    type = Column(String(20))
    __mapper_args__ = {
    'polymorphic_on':type,
    'polymorphic_identity':'content',
    'with_polymorphic':'*'
}


class Locality(Content):
    __tablename__ = "local"
    id = Column(Integer, ForeignKey('content.id'),primary_key=True)

    city_name = Column(Unicode(80))
    __mapper_args__ = {'polymorphic_identity':'city'}

现在我使用alembic删除了Locality表。 每次我查询内容时,我都会

AssertionError: No such polymorphic_identity 'city' is defined

如何删除此polymorphic_identity

1 个答案:

答案 0 :(得分:0)

我通过My​​SQL控制台对内容应用MySQL'delete from'命令,找到类型为'city'的内容

来解决这个问题
delete from content where content.type='city';