Hi Simon/all,

When I run your example i get:

Traceback (most recent call last):
   File "/var/www/PyWebOs/caltst.py", line 41, in <module>
     cal = Calendar()
   File "<string>", line 4, in __init__
   File "/usr/local/lib/python2.6/site-packages/sqlalchemy/orm/ 
state.py", line 71, in initialize_instance
     fn(self, instance, args, kwargs)
   File "/usr/local/lib/python2.6/site-packages/sqlalchemy/orm/ 
mapper.py", line 1810, in _event_on_init
     instrumenting_mapper.compile()
   File "/usr/local/lib/python2.6/site-packages/sqlalchemy/orm/ 
mapper.py", line 666, in compile
     "Message was: %s" % mapper._compile_failed)
InvalidRequestError: One or more mappers failed to compile.  Exception  
was probably suppressed within a hasattr() call. Message was: One or  
more mappers failed to compile.  Exception was probably suppressed  
within a hasattr() call. Message was: One or more mappers failed to  
compile.  Exception was probably suppressed within a hasattr() call.  
Message was: Could not find table 'Calendar' with which to generate a  
foreign key


So I am starting to get the impression there is something wrong beyond  
my code.

Your and my example are ruling out MySQL (or the Mysql part of  
SQLAlchemy)

Now there is python 2.6.2 and SQLA version 0.5.6 on a Linux box....
Anyone having trouble with these versions?


Martijn


On Oct 15, 2009, at 4:10 PM, King Simon-NFHD78 wrote:

>
> import sqlalchemy as sa
> import sqlalchemy.orm as orm
> from sqlalchemy.ext.declarative import declarative_base
>
> Base = declarative_base()
>
> class XProp(Base):
>    __tablename__  = "CalendarXProps"
>    Id = sa.Column(sa.Integer, primary_key=True)
>    EventId = sa.Column(sa.ForeignKey('CalendarEvents.Id'))
>    AlarmId = sa.Column(sa.ForeignKey('CalendarAlarms.Id'))
>    CalendarId = sa.Column(sa.ForeignKey('Calendars.Id'))
>    Name = sa.Column(sa.String(20))
>    Value = sa.Column(sa.String(20))
>
> class Event(Base):
>    __tablename__ = "CalendarEvents"
>    Id = sa.Column(sa.Integer, primary_key=True)
>    CalendarId = sa.Column(sa.ForeignKey('Calendars.Id'))
>    XProps = orm.relation(XProp, backref='Events')
>
> class Alarm(Base):
>    __tablename__ = "CalendarAlarms"
>    Id = sa.Column(sa.Integer, primary_key=True)
>    CalendarId = sa.Column(sa.ForeignKey('Calendars.Id'))
>    XProps = orm.relation(XProp, backref='Alarms')
>
> class Calendar(Base):
>    __tablename__ = "Calendars"
>    Id = sa.Column(sa.Integer, primary_key=True)
>    Events = orm.relation(Event, backref='Calendar')
>    Alarms = orm.relation(Alarm, backref='Calendar')
>    XProps = orm.relation(XProp, backref='Calendar')
>
> if __name__ == '__main__':
>    engine = sa.create_engine('sqlite:///')
>    Base.metadata.create_all(bind=engine)
>    Session = orm.sessionmaker(bind=engine)()
>
>    cal = Calendar()
>    cal.Events.append(Event(XProps=[XProp(Name='Hello', Value='World'),
>                                    XProp(Name='foo', Value='bar')]))
>
>
>    Session.add(cal)
>    Session.flush()
>
>    print cal
>    for event in cal.Events:
>        print event
>        for prop in event.XProps:
>            print prop


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to