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

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

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

    数据库 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   ·   实用小工具   ·   1511 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:04 · PVG 01:04 · LAX 10:04 · JFK 13:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.