strange SqlAlchemy update behaviour
Posted
by Max
on Stack Overflow
See other posts from Stack Overflow
or by Max
Published on 2010-04-08T13:06:43Z
Indexed on
2010/04/08
13:23 UTC
Read the original article
Hit count: 422
I'm new to SqlAlchemy and Elixir, so I've started from tutorial and tried to create table, insert a record, and then update it as follows:
#'elixir_test.py'
from elixir import *
metadata.bind = "postgresql://myuser:mypwd@localhost:5432/dbname"
metadata.bind.echo = True
class Movie(Entity):
title = Field(Unicode(30))
year = Field(Integer)
description = Field(UnicodeText)
def __repr__(self):
return '<Movie "%s" (%d)>' % (self.title, self.year)
and in another file in the same directory:
from elixir_test import *
setup_all()
#create table
create_all()
Movie(title=u"Blade Runner", year=1982)
#add record
session.commit()
#get records
Movie.query.all()
#trying to update record and commit changes, BUT...
movie = Movie.query.first()
movie.year = 1983
session.commit()
#now we have two records in our table, one
#with year=1982 and one with year=1983
Movie.query.all()
What did I missed?
© Stack Overflow or respective owner