SQLAlchemy批量插入失败

apo*_*kul 3 python sqlalchemy

我在循环中使用SQLAlchemy进行批量插入,如下所示:

for table, batch in pendingInserts:
    self.conn.execute(table.insert(), batch)
Run Code Online (Sandbox Code Playgroud)

这里batch是名单dicttable是SQLAlchemy的表.第一批插入成功执行但在后续迭代中,同一表上的insert失败,并出现以下错误:

StatementError: A value is required for bind parameter 'security_exchange', in parameter group 45 (original cause: InvalidRequestError: A value is required for bind parameter 'security_exchange', in parameter group 45) u'INSERT INTO .....

security_exchange是DB(PostgreSQL)中的可空列,因此它不是必需的,并且在批处理中的所有条目中都被省略.我很困惑为什么它成功第一次批量插入但在同一个表上第二次插入失败.同样对于同一个表,对于所有批次中的所有dicts,提供的列数始终保持相同.

apo*_*kul 7

批量插入需要所有项目为批次中的所有项目提供相同的列集.在我的情况下,批处理中的某些项目会跳过某些可选列(具有默认值).