Я пытаюсь использовать рецепт управления версиями, описанный на веб-сайте sqlalchemy (http://www.sqlalchemy.org/docs/orm/examples.html#versioned-objects) вместе с моделью многоуровневого наследования (наследование объединенной таблицы)
Вот мои декларативные утверждения:
class Sample(Base):
__metaclass__ = VersionedMeta
__tablename__ = 'sample'
__table_args__ = {'schema': 'test'}
id = Column(Integer, primary_key=True)
discriminator = Column('type', String(50))
token = Column(String(128), nullable=False)
source_sample_id = Column(Integer, ForeignKey('test.sample.id'))
children = relationship("Sample", backref=backref('source_sample', remote_side=id), single_parent=True)
__mapper_args__ = {'polymorphic_on': discriminator, 'polymorphic_identity':'sample'}
def __init__(self, token, source_sample_id=None):
self.token = token
self.source_sample_id = source_sample_id
class Tissue(Sample):
__metaclass__ = VersionedMeta
__tablename__ = 'tissue'
__mapper_args__ = {'polymorphic_identity': 'tissue'}
__table_args__ = {'schema': 'test'}
id = Column(Integer, ForeignKey('test.sample.id'), primary_key=True)
concentration = Column(String(32))
def __init__(self, token, concentration, source_sample_id=None):
super(Sample, self).__init__(token, source_sample_id)
self.concentration = concentration
class LeukemicTissue(Tissue):
__metaclass__ = VersionedMeta
__tablename__ = 'leukemic_tissue'
__mapper_args__ = {'polymorphic_identity': 'leukemic_tissue'}
__table_args__ = {'schema': 'test'}
id = Column(Integer, ForeignKey('test.tissue.id'), primary_key=True)
leukemia = Column(String)
def __init__(self, token, concentration, leukemia, source_sample_id=None):
super(Tissue, self).__init__(token, concentration, source_sample_id)
self.leukemia = leukemia
Всякий раз, когда я пытаюсь "create_all ()", я получаю следующую ошибку: sqlalchemy.exc.ArgumentError: Невозможно найти какие-либо отношения внешнего ключа между 'fabric_history' и 'leucegene_tissue_history'.
Одноуровневое наследование работает прекрасно (то есть: если я остановлюсь на "Tissue" и не объявлю "LeukemicTissue"), но мне действительно нужна многоуровневая схема наследования для работы ..
Можеткто-нибудь подскажет?
Спасибо !!