簡體   English   中英

SQLAlchemy:如何在具有IDENTITY主鍵列的Sybase數據庫表中插入新行?

[英]Sqlalchemy: How to insert a new row into a Sybase database table which has an IDENTITY primary key column?

我已經定義了此類:

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')
...

當我嘗試將新的Trade實例提交回數據庫時,出現以下錯誤:

    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.

我想我錯過了ID列定義中的某些內容。 解決辦法是什么?

編輯:

台式電腦:WinXP

Sybase服務器:15.5

原來是驅動程序問題。

Sybase ODBC驅動程序12.5適用於簡單的選擇和更新,但在將數據插入具有標識列的表中時會失敗。

切換到15.5驅動程序解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM