On Mar 31, 2011, at 9:31 PM, Inside Zhou wrote:
> First I try to create a table like this:
> user_table = Table('user', metadata,
> Column('id', Integer),
> Column('name', Unicode)
> )
>
> then I discards the table in metadata and reload it by reflection with
> overriding:
>
> user_table = Table('user', metadata,
> Column('id', Integer, primary_key=True),
> Column('name', Unicode),
> autoload=True
> )
>
> create a mapper,a session and insert a row with values(None,'jack'),retrieve
> this row by:
> "user_table.user_table.select().execute()"
>
> all code is done successfully at this time.
so there's no bug. table object works fine.
>
> next I try get the row by a session:
> "s.query(User).all()"
>
> but I get nothing.
>
is this SQLite ? it suggests you're storing NULL for the primary key.
tables dont "autoincrement" unless special directives are used - SQLite needs
INTEGER PRIMARY KEY, Postgresql needs SERIAL, MySQL need AUTOINCREMENT.
SQLAlchemy issues these directives when Integer, primary_key=True is used
during the create.
>
> --
> 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.
--
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.