the TRADE table needs the "id" column to be an IDENTITY column, otherwise you 
have to populate Trade.id with an explicit value.

background on IDENTITY: 
http://infocenter.sybase.com/archive/index.jsp?topic=/com.sybase.infocenter.dc00170.1260/html/iqapg/iqapg491.htm

Also its very likely you want to be using case insensitive table names, which 
means all lower case - "trade", "instrument", etc.   Then you won't need that 
"quote=False" option.   The docstrings for "quote" at 
docs.sqlalchemy.org/en/rel_0_7/core/schema.html describe what it means to be 
"case sensitive" vs. "case insensitive".

On May 9, 2012, at 7:31 AM, Anthony Kong wrote:

> I did not realisd the mailing list is in google groups after I posted my 
> question on SO:
>  
> http://stackoverflow.com/questions/10509016/sqlalchemy-how-to-insert-a-new-row-into-a-sybase-database-table-which-has-an-id
>  
> Hopefully more sqlalchemy experts hang out here. I will reproduce my question 
> here:
>  
>  
> = Question: ==============================================
>  
>  
> I have defined this class:
> 
> class Trade(Base): 
>     __tablename__ = 'TRADE' 
>     __table_args__ = {'quote':False} 
>  
>     id = Column(Integer, name='id_trade', primary_key=True) 
>     idImnt = Column(Integer, ForeignKey('INSTRUMENT.id_imnt'), 
> name='id_imnt') 
> ... 
> When I tried to commit a new Trade instance back into database, I got this 
> error:
> 
>     Instance <Trade at 0x954fd90> has a NULL identity key.  If this is  
> an auto-generated value, check that the database table allows generation of  
> new primary key values, and that the mapped Column object is configured to  
> expect these generated values.  Ensure also that this flush() is not  
> occurring at an inappropriate time, such as within a load() event. 
> I think I missed something in the id column definition. What is the solution?
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/sqlalchemy/-/0cYedubox3YJ.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> 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 sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to