On 8/6/2010 9:04 PM, Michael Hipp wrote:
Can someone help me figure out why I keep getting the error below. Here
are my 3 models. It's a simple many-one on banks-dealer and reps-dealer.

class Dealer(Base):
__tablename__ = 'dealers'
id_ = Column(Integer, primary_key=True)
reps = relationship('Rep', order_by='Rep.lname', backref="dealer")
banks = relationship('Bank', order_by='Bank.id_', backref="dealer")

class Bank(Base):
__tablename__ = 'banks'
id_ = Column(Integer, primary_key=True)
dealer_id = Column(Integer, ForeignKey('dealers.id_'))
dealer = relationship(Dealer, backref=backref('banks', order_by=id_))

class Rep(Base):
__tablename__ = 'reps'
id_ = Column(Integer, primary_key=True)
dealer_id = Column(Integer, ForeignKey('dealers.id_'))
dealer = relationship(Dealer, backref=backref('reps', order_by=id_))

I'm attempting to do this exactly like:
http://www.sqlalchemy.org/docs/ormtutorial.html#building-a-relationship

But when I run it it gives:
sqlalchemy.exc.ArgumentError: Error creating backref 'dealer' on
relationship 'Dealer.reps': property of that name exists on mapper
'Mapper|Rep|reps'

I think I figured it out, it's not necessary to put the backref on both ends.

Michael

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to