V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
tianxin8431
V2EX  ›  问与答

关于 peewee 事务的问题

  •  
  •   tianxin8431 · May 11, 2021 · 1238 views
    This topic created in 1815 days ago, the information mentioned may be changed or developed.

    想请教老哥们一个问题,

    with Ext.db.atomic():
                ...
                BranchInfo.insert(branch_id=branch_id, school_id=school_id,
                                branch_name=branch_name, branch_type=branch_type, person_count=person_count).execute()
                SchoolInfo.update(person_count=SchoolInfo.person_count +
                                person_count).where(SchoolInfo.school_id == school_id).execute()
                Statistics.insert(branch_or_school_id=branch_id, issue_no=issue_no).execute()
    

    我用 peewee 的事务写库的时候,会出现很奇怪的现象,似乎会存在只写了Statistics表,而另外两个表没有写入的情况,再写一次就提示重复的 index (我在字段branch_or_school_id上加了 unique )。想问下老哥们,为什么会出现这种情况呢?

    2 replies    2021-05-11 19:12:36 +08:00
    ebingtel
        1
    ebingtel  
       May 11, 2021
    那确定这三个 Model class 用的是同一个 db 对象么?
    sql 语句的日志打出来看看呢?
    tianxin8431
        2
    tianxin8431  
    OP
       May 11, 2021
    @ebingtel 是同一个 db 对象,蛋疼的就是用阿里云之后没法查 log
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   801 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:34 · PVG 04:34 · LAX 13:34 · JFK 16:34
    ♥ Do have faith in what you're doing.