peewee_async get_or_create断言错误

时间:2018-11-17 13:57:24

标签: python asynchronous peewee

我正在尝试创建一个简单的异步get_or_create:

database = Bot.database

class Settings(Bot):
    guild_name = peewee.TextField(default="None")
    guild_id = peewee.BigIntegerField(primary_key=True, unique=True)

    class Meta:
        database = database

class UserDB(Bot):
    guild_id = peewee.ForeignKeyField(Settings, default=0, 
                                      on_update='CASCADE', on_delete='CASCADE')
    member_id = peewee.BigIntegerField(default=0)

    class Meta:
        primary_key = peewee.CompositeKey('member_id', 'guild_id')
        database = database

db = peewee_async.Manager(database)

database.set_allow_sync(False)

async def modactiondb(ctx, member, newcase, action, time=None):
    await db.get_or_create(UserDB, guild_id=ctx.guild.id, member_id=member.id)

但是,如果条目不在数据库中,我总是会收到一个AssertionError

AssertionError: Error, sync query is not allowed! Call the `.set_allow_sync()` or use the `.allow_sync()` context manager.

经过几天令人沮丧的测试,也许有人可以向我解释我的错误原因是什么。

0 个答案:

没有答案