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

2017-08-30 11:06:21 +08:00
 pleasurelong

数据库 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.

1667 次点击
所在节点    问与答
1 条回复
pleasurelong
2017-08-30 11:15:09 +08:00
解决了 多谢,因为 我的待添加对象里面已经包含这个 vid 了,所以得去掉再添加就行了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/386818

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX