在 django 的异步函数中创建对象时获取 SynchronousOnlyOperation

问题描述 投票:0回答:0

运行时:

async def func():
    print("This is async function")
    Program.objects.create(name="New Program")


asyncio.run(func())

得到这个:

Error : SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

谁能帮我解决这个问题?

python django asynchronous python-asyncio
© www.soinside.com 2019 - 2024. All rights reserved.