Hi. I have two tables that have foreign keys on each other. The following works fine, where Base is a declarative base: class Child1(Base): __tablename__ = 'child1' id = Column('id', Integer, primary_key=True) related_child2 = Column('c2', Integer, ForeignKey('child2.id', use_alter = True, name='c2_key'))
class Child2(Base): __tablename__ = 'child2' id = Column('id', Integer, primary_key=True) related_child1 = Column('c1', Integer, ForeignKey('child1.id')) I would like these tables to both be children of a common parent table using join inheritance, but I still want them to reference each other directly. If I change the model to this: class Parent(Base): __tablename__ = 'parent' id = Column('id', Integer, primary_key=True) tp = Column('type', String(50)) __mapper_args__ = dict(polymorphic_on = tp) class Child1(Parent): __tablename__ = 'child1' id = Column('id', Integer, ForeignKey('parent.id'), primary_key=True) related_child2 = Column('c2', Integer, ForeignKey('child2.id', use_alter = True, name='c2_key')) __mapper_args__ = dict(polymorphic_identity = 'child1') class Child2(Parent): __tablename__ = 'child2' id = Column('id', Integer, ForeignKey('parent.id'), primary_key=True) related_child1 = Column('c1', Integer, ForeignKey('child1.id')) __mapper_args__ = dict(polymorphic_identity = 'child2') It no longer works. In particular, I get <class 'sqlalchemy.exceptions.InvalidRequestError'>: Could not find table 'child2' with which to generate a foreign key Why was it able to find the table in the first model but not in the second? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---