Alembic 迁移:如何删除多态身份
Alembic Migration: How to remove polymorphic Identity
我有以下设置
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 table。
每次查询内容时,我都会得到
AssertionError: No such polymorphic_identity 'city' is defined
如何删除这个 polymorphic_identity
我通过 MySQL 控制台对内容应用 MySQL 'delete from' 命令来解决这个问题,找到类型为 'city'
的那些内容
delete from content where content.type='city';
我有以下设置
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 table。 每次查询内容时,我都会得到
AssertionError: No such polymorphic_identity 'city' is defined
如何删除这个 polymorphic_identity
我通过 MySQL 控制台对内容应用 MySQL 'delete from' 命令来解决这个问题,找到类型为 'city'
的那些内容delete from content where content.type='city';