Hello,
I am working in eclipse IDE.
I have this code in the file :
class User(Base):
__tablename__ = 'users'
id = Column('user_id',Integer,primary_key = True)
name = Column('user_name',String(20))
addresses = relationship("Address")
def __repr__(self):
return "<User(%s)>" % self.name
session = Session(bind=engine)
u=User('myname')
session.add(u)
session.flush()
print u.id
I ran this file and it worked fine but then I changed
something.
Now to see the effect I have to run file again and then I
noticed this
Instead of adding two different objects with two different
ids but same name. It simply updated the id of already existing object.
Now I have two questions :
1. What is the reason of this behavior? First of all it should have
made two different objects . But I think it did not do that because it thought
this object is similar to existing one. In that case it should have raised
exception instead of simply my primary key.
2. WHat happened when I ran the file again? It created a brand new
session or continued the previous one?
3. Due to problem mentioned in point no 1. it wasted my early id nos as
when I committed it saved the last one?
I know there is something that I am missing here as I am just a beginner in
sqlalchemy.
Thanks in advance.
Regards,
Manav Goel
--
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.