【问题标题】:Sqlalchemy: How to insert a new row into a Sybase database table which has an IDENTITY primary key column?Sqlalchemy:如何将新行插入到具有 IDENTITY 主键列的 Sybase 数据库表中?
【发布时间】:2012-05-09 02:15:25
【问题描述】:

我已经定义了这个类:

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

【问题讨论】:

    标签: python sqlalchemy sybase python-2.6


    【解决方案1】:

    原来是驱动问题。

    Sybase ODBC 驱动程序 12.5 适用于简单的选择和更新,但在将数据插入具有标识列的表时会失败。

    切换到 15.5 驱动程序解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 2014-10-03
      • 2019-01-14
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多