Thanks Mike for the quick reply. I have changed the code so it uses backref on one side. The models now get created w/o error. I haven't actually tested using the relationship but I'm sure it's fine now.
For anyone else with this problem, here's the 'fixed' code. I didn't change the Artifact_Reference table, it's the same as posted above. I'm not keen on the naming master/slave.. maybe primary/secondary would be better.. It's not exactly Parent/Child.. heh. class Artifact_Relation(Base): __tablename__ = 'artifact_relation' master_artifact_id = Column( Integer, ForeignKey('artifact.id', name='artifact_relation_master_id_fk', ondelete="cascade", onupdate="cascade"), primary_key=True, nullable=False ) slave_artifact_id = Column( Integer, ForeignKey('artifact.id', name='artifact_relation_slave_id_fk', ondelete="cascade", onupdate="cascade"), primary_key=True, nullable=False ) relationship_type = Column(String(24), nullable=False) slave = relationship("Artifact", backref=backref("masters"), foreign_keys=[slave_artifact_id]) master = relationship("Artifact", backref=backref("slaves"), foreign_keys=[master_artifact_id]) class Artifact(Base): "Artifact" __tablename__ = 'artifact' id = Column('id', Integer, primary_key=True) artifact_type = Column('artifact_type', String(16), nullable=False) __mapper_args__ = { 'polymorphic_on': artifact_type } artifact_references = relationship( 'Artifact_Reference', back_populates='artifact', cascade="all, delete-orphan", passive_deletes=True ) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.