0

私はこのクラスを定義しました:

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 列の定義に何かが欠けていたと思います。解決策は何ですか?

編集:

デスクトップ PC: WinXP

サイベース サーバー: 15.5

4

1 に答える 1

0

ドライバーの問題であることが判明しました。

Sybase ODBC ドライバー 12.5 は、単純な選択と更新では問題なく動作しますが、ID 列を含むテーブルへのデータの挿入に関しては失敗します。

15.5 ドライバーに切り替えると、問題は解決しました。

于 2012-05-10T12:12:27.700 に答える