Christoph Haas wrote:
>
> So apparently SQLAlchemy tries to insert a new row with the "id" field
> being "None". This is obviously wrong because the field is supposed to
> contain the next serial value. I enabled debugging and saw that before
> the insert SQLAlchemy runs:
>
> ___SQL___ sqlalchemy.engine.base.Engine.0x...3b8c: select
> nextval('"myobject_id_seq"')
> ___SQL___ sqlalchemy.engine.base.Engine.0x...3b8c: None
>
> I was curious and ran that SELECT statement in a "psql" shell directly
> on the database server and correctly received:
>
> mydatabase=# select nextval('"myobject_id_seq"');
> nextval
> ---------
> 358
> (1 row)
>
> After hours of digging around in my code, reinstalling psycopg2 and
> writing test cases I'm stuck somehow. How come SQLAlchemy fails to find
> the next ID of that column?
>
> Thanks in advance for any insight.
Unfortunately there's not enough information here to diagnose your issue.
The sequence is executed before an INSERT if you did not explicitly pass
None to the primary key column, but if None were passed then the sequence
isn't consulted (and you wouldn't see it in the log for that statement).
In the log, you should see the "nextval" and "None" combination directly
above each INSERT for which you expect to see a value (the None represents
the parameters sent to the statement, None in the case of a sequence
execute). For further detail we would have to see exactly how you are
creating and executing this insert statement (or alternatively, an example
of the ORM usage which results in this statement).
--
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.