【问题标题】:Alembic Migration: How to remove polymorphic IdentityAlembic 迁移:如何删除多态身份
【发布时间】:2015-11-11 07:20:34
【问题描述】:

我有以下设置

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 表。 每次我查询内容时,我都会得到 ​​p>

AssertionError: No such polymorphic_identity 'city' is defined

如何删除这个 polymorphic_identity

【问题讨论】:

    标签: sqlalchemy alembic


    【解决方案1】:

    我通过 MySQL 控制台对内容应用 MySQL 'delete from' 命令来解决这个问题,找到类型为 'city' 的内容

    delete from content where content.type='city';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-06
      • 2013-07-04
      • 2018-06-11
      • 2020-02-17
      • 2014-12-02
      • 1970-01-01
      • 2018-08-17
      相关资源
      最近更新 更多