Hi, As you are defining Country when you use it within your relation, you need to define your relation like this :
parent = relation("Country", backref=backref('child'), cascade="all") Note the quotes around Country. Regards, Laurent Cedric a écrit : > Hi, > > I'm trying to migrate my TurboGears project from SQLObject to > SQLAlchemy. As the TurboGears2 way of using SQLAlchemy is the > DeclarativeBase, I'm trying to achive a self-referential using the > DeclarativeBase. Following the documentation, it seems that the > following code "could" be correct (after a translation from the Base > example), but in fact, it complains that the "Country" name is not > defined... > > File "/is2dev/dev/model/model.py", line 47, in Country parent = > relation(Country, backref=backref('child'), cascade="all") > NameError: name 'Country' is not defined > > I just try to make a tree with the world > continents > regions > > countries. > > class Country(DeclarativeBase): > """ > Country with iso and related region > """ > __tablename__ = 'countries' > > #{ Columns > id = Column(Integer, primary_key=True) > name = Column(Unicode(100), nullable=False) > iso = Column(Unicode(3), nullable=False) > created = Column(DateTime(), default=datetime.now(), > nullable=False) > updated = Column(DateTime(), nullable=True) > #{ Relations > parent_id = Column(Integer, ForeignKey('countries.id'), > nullable=True) > parent = relation(Country, backref=backref('child'), > cascade="all") > #{ Special methods > > #} > > Thanks for your help... > Regards > Cédric > > > > --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---