await room.save()
显示以下错误 AttributeError: 'NoneType' object has no attribute 'execute_insert'
启动代码
async def init():
# Here we create a SQLite DB using file "db.sqlite3"
# also specify the app name of "models"
# which contain models from "app.models"
await Tortoise.init(
db_url='sqlite://db1',
modules={'app1': ['app1.models']}
)
# Generate the schema
#await Tortoise.generate_schemas()
@app.on_event("startup")
async def startup_event():
nest_asyncio.apply()
run_async(init())
创建了一个数据库结构,这就是为什么评论等待 Tortoise.generate_schemas()。在下面找到我的发布方法代码
@app.post("/room/{room_id}")
async def post(request: Request, room_id):
room = models.Room(id=room_id)
await room.save()
return {"message":"created successfully"}