V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
pleasurelong
V2EX  ›  问与答

flask sqlalchemy flush 之后获取不到 id 是怎么回事?一直为 0

  •  
  •   pleasurelong · 2017-08-30 11:06:21 +08:00 · 1999 次点击
    这是一个创建于 3025 天前的主题,其中的信息可能已经有所发展或是发生改变。

    数据库 mysql,vid 为自增的主键

    video_info.update({'status': 1}) _video = UserVideo(**video_info) db.session.add(_video)

    db.session.commit()

    db.session.flush() _vid = _video.vid

    print(_video.path, _vid)

    _vid 一直为 0.

    1 条回复    2017-08-30 11:15:09 +08:00
    pleasurelong
        1
    pleasurelong  
    OP
       2017-08-30 11:15:09 +08:00
    解决了 多谢,因为 我的待添加对象里面已经包含这个 vid 了,所以得去掉再添加就行了。
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   878 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:39 · PVG 05:39 · LAX 13:39 · JFK 16:39
    ♥ Do have faith in what you're doing.