pleasurelong
V2EX  ›  问与答

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

  •  
  •   pleasurelong · Aug 30, 2017 · 2194 views
    This topic created in 3181 days ago, the information mentioned may be changed or developed.

    数据库 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 replies    2017-08-30 11:15:09 +08:00
    pleasurelong
        1
    pleasurelong  
    OP
       Aug 30, 2017
    解决了 多谢,因为 我的待添加对象里面已经包含这个 vid 了,所以得去掉再添加就行了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2845 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:25 · PVG 23:25 · LAX 08:25 · JFK 11:25
    ♥ Do have faith in what you're doing.