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?
Edit:
Desktop PC: WinXP
Sybase Server: 15.5
It turned out to be a driver issue.
Sybase ODBC driver 12.5 works fine for simple select and update, but will fail when it comes to inserting data into a table with identity column.
Switching to 15.5 driver solved the issue.