On Tue, 28 Nov 2006 11:01:29 +0100
Julien Cigar <[EMAIL PROTECTED]> wrote:

> 
> I think that the problem is with the start_date column.
> 
> c.start_date=time.asctime() is not a valid DateTime, you have to use
> datetime.today() or something like that. SQLAlchemy (psycopg in fact)
> maps timestamps with DateTime objects.
> 
> 

Thanks for your answer, but the problem is another. 
It's my brain, I wrote c.user_id=u instead c.user=u.

I solved the problem.


> Enrico Morelli wrote:
> > Dear all,
> >
> > I've a strange problem with session.flush() that I'm not able to
> > understand why. I've the following tables
> >
> > users=Table('users', metadata,
> >  Column('user_id', Integer, primary_key=True),
> >  Column('firstname', String),
> >  Column('lastname', String),
> >  Column('login', String),
> >  Column('uid', Integer),
> >  Column('gid', Integer),
> >  Column('password', String),
> >  Column('email', String),
> >  Column('institute', String),
> >  Column('nationality', String),
> >  Column('home_directory', String),
> >  Column('category', String(1)))
> >  
> >   
> > calculation=Table('calculations', metadata,
> >  Column('calculation_id', Integer, primary_key=True),
> >  Column('user_id', Integer,  ForeignKey('users.user_id'),
> > primary_key=True), 
> >  Column('program', String),
> >  Column('job', String),
> >  Column('workdir', String),
> >  Column('start_date', DateTime),
> >  Column('protein', String),
> >  Column('status', String(1)))
> >
> >
> > So, I create the engine and so on.
> >
> > engine=create_engine('postgres://[EMAIL PROTECTED]/db')
> > metadata=BoundMetaData(engine)
> > session=create_session()
> >
> > users=Table('users', metadata, autoload=True)
> > calculations=Table('calculation', metadata, autoload=True)
> >
> > class Users(object): pass
> > class Calculations(object): pass
> >
> > mapper(Users, users)
> > mapper(Calculations, calculations, properties={'user':
> > relation(Users)})
> >
> > u=session.query(Users).get_by(login='rossi')
> > c=Calculations()
> > c.job='1234'
> > c.user_id=u
> > c.start_date=time.asctime()
> > c.program='cara'
> > c.workdir='/home/morelli'
> > c.protein='test'
> > c.status='R'
> > session.save(c)
> > session.flush()
> >
> > SQLError: (ProgrammingError) can't adapt 'INSERT INTO calculations
> > (calculation_id, user_id, job, workdir, start_date, protein, status,
> > program) VALUES (%(calculation_id)s, %(user_id)s, %(job)s,
> > %(workdir)s, %(start_date)s, %(protein)s, %(status)s,
> > %(program)s)' {'status': 'R', 'workdir': '/home/morelli',
> > 'user_id': <__main__.Users object at
> > 0xb75d55cc>, 'calculation_id': 11L, 'job': '1234', 'program':
> > 0xb75d55cc>'cara',
> > 'protein': 'test', 'start_date': 'Tue Nov 28 09:59:07 2006'}
> >
> > If I do the same thing by hand under psql, it's works fine.
> > Where is the problem?
> >
> > Thanks
> >   
> 
> 


-- 
-------------------------------------------------------------------
       (o_
(o_    //\  Coltivate Linux che tanto Windows si pianta da solo.
(/)_   V_/_
+------------------------------------------------------------------+
|     ENRICO MORELLI         |  email: [EMAIL PROTECTED]       |
| *     *       *       *    |  phone: +39 055 4574269             |
|  University of Florence    |  fax  : +39 055 4574253             |
|  CERM - via Sacconi, 6 -  50019 Sesto Fiorentino (FI) - ITALY    |
+------------------------------------------------------------------+

--~--~---------~--~----~------------~-------~--~----~
 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to