user_id should be an int.  if a string, you have to set user_id  
explicitly.

im not sure what tutorial you're looking at, the SQLA 0.4.8 tutorial 
(http://www.sqlalchemy.org/docs/04/ormtutorial.html 
  ) illustrates the user table as:

users_table = Table('users', metadata,
...     Column('id', Integer, primary_key=True),
...     Column('name', String(40)),
...     Column('fullname', String(100)),
...     Column('password', String(15))
... )



On May 3, 2009, at 9:22 AM, Sverre wrote:

>
> I tried the tutorial for version 0.4.8  but the example doesnt work
> for me. So  I simplified the code the code a little bit but with
> session.commit I get always an exception, because sqlalchemy tries to
> insert a none into user_name and nothing into the primary key. Could
> someone help me?
>
> #==========
> lfrom sqlalchemy import *
> from sqlalchemy.orm import *
>
> engine = create_engine('sqlite:///:memory:', echo=True)
>
> metadata = MetaData()
>
> users_table = Table('users', metadata,
>    Column('user_id', String(4), primary_key = True),
>    Column('user_name', String(16), nullable = False),
> )
>
> metadata.create_all(engine)
>
> class User(object):
>    def __init__(self, id,  name):
>        self.id = id
>        self.name = name
>
>    def __repr__(self):
>        return "<User('%4s','%16s')>" % (self.id, self.name)
>
> m= mapper(User, users_table)
>
> Session = sessionmaker(bind=engine, autoflush=True,
> transactional=True)
>
> session= Session()
> print User(id='ed',name='Ede Myers')
>
> session.save(User(id='ed', name='Ede Myers'))
> session.commit()
> session.close()
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to