Excerpts from jo's message of Fri Apr 23 03:16:21 -0300 2010:
> Hi all,
>
> I need to insert a new row and get back the last inserted id,
> I have some difficulty using the flush(), then I'm trying with commit() but
> I can't understand how commit() works in 0.6.
> In the following script I try to update a row and it works properly
> but when I try to insert a new one, it doesn't work,
> there's no messages but the row is not inserted into the table.
> Is this the right way ?
>
>
> from sqlalchemy.orm import sessionmaker
> Session = sessionmaker(autoflush=True)
> session = Session()
>
> #update an existing row... it works
> old = Specie.get('D')
> old.specie_descrizione='dog'
>
> #insert a new row... it doesn't work
> new=Specie(
> specie_codice='C',
> specie_descrizione='cat'
> )
>
> session.commit()
>
> thanks for any help
>
> j
>
You forgot to add the instance to the session before the commit. See
http://www.sqlalchemy.org/docs/ormtutorial.html#adding-new-objects
--
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.