map the "user" column to another name, since your "user" relation is blocking it.
Kashif wrote: > > Yes, I did that and that is what causes problems, I am attaching the > actual mapping underneath. Note the email object has a user object. > Any thoughts? > > user_table = sa.Table('user', meta.metadata, > sa.Column('id', types.String(50), primary_key=True), > sa.Column('username', types.String(255)), > sa.Column('password', types.String(255)), > ) > > email_table = sa.Table('email', meta.metadata, > sa.Column('user', types.String(50), sa.ForeignKey('user.id')), > sa.Column('email', types.String(50), primary_key=True), > ) > > Thanks > Kashif > > On Apr 6, 8:18 pm, "Michael Bayer" <mike...@zzzcomputing.com> wrote: >> Kashif wrote: >> >> > Tried that already, I get an error: >> >> > InterfaceError: (InterfaceError) Error binding parameter 1 - probably >> > unsupported type. u 'INSERT INTO emails (address, user) VALUES >> > (?, ?)' ['....@ped.com', <__main__.User object at 0x92edcec>] >> >> > or I get a ProgrammingError that says something like 'cant adapt...' >> >> > PS: I am interested in the non-declarative style >> >> if you'd like to store a User object on an attribute named "user", then >> you can't map that attribute to a column named "user". you need to >> construct a foreign key on your table. please read: >> >> http://www.sqlalchemy.org/docs/05/mappers.html#many-to-one >> >> >> >> > On Apr 6, 7:44 pm, "Michael Bayer" <mike...@zzzcomputing.com> wrote: >> >> Kashif wrote: >> >> >> > Hi, >> >> > I have tried all kinds of tutorials, but I cant get two simple >> tables >> >> > mapped. >> >> >> pretty much this exact example is present in *the* tutorial which is >> the >> >> ORM tutorial athttp://www.sqlalchemy.org/docs/. >> >> >> > Here are the tables: >> >> >> > class User(object): >> >> > def __init__(self,username,password): >> >> > self.username = username >> >> > self.password = password >> >> >> > class Email(object): >> >> > def __init__(self, address, user): >> >> > self.address = address >> >> > self.user = user >> >> >> > All I wish to accomplish is the following: >> >> >> > tom_user = User("tom","passy") >> >> > tom_email = Email("t...@someemail.com", tom_user) >> >> > session.add(tom_user) >> >> > session.add(tom_email) >> >> > session.commit() >> >> >> > But this doesnt work, can someone flesh out the tables and the >> mapping >> >> > for me so I know what I am doing wrong. >> >> >> > Thanks >> >> > Kashif > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---