zoukankan      html  css  js  c++  java
  • sqlalchemy 踩过的坑

    记录下Sqlalchemy遇到的问题,不定时更新。


     设置主键为非自增

     sqlalchemy 在sql server中默认主键是自增的,如果在数据库设置的主键不是自增的,这个时候插入就会出现异常:

     提示does not have the identity property

     这个时候需要在主键中设置autoincrement=False,显示表示非自增,才能正常写入


     不要使用in_查询一个空的可迭代对象

    例如:

    db.session.query(Object).filter(Object.Id.in_(ids)).delete(synchronize_session=False)

    当ids为空的可迭代的对象时,就会出现如下警告,提示有性能问题

    SAWarning: The IN-predicate on "xxxx.Id" was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.  Consider alternative strategies for improved performance.

    在创建这个语句之前做个判断,判断ids是不是为空。

  • 相关阅读:
    Activity之间的数据传递
    解析JSON
    使用HTTP协议访问网路
    WebView的初体验
    Alarm机制用于定时服务
    IntentService和Service执行子线程对比
    前台服务
    Android四大组件之服务
    异步消息处理机制,UI更新
    Git学习
  • 原文地址:https://www.cnblogs.com/blackmatrix/p/6907156.html
Copyright © 2011-2022 走看看