愿与君长安
2021-06-24 19:25
def create_city(db: Session, city: schemas.CreateCity): db_city = models.City(**city.dict()) print("*" * 50) print("start") print(db_city) db.add(db_city) print("add") db.commit() print("commit") db.refresh(db_city) print("refresh") print(db_city) print("end") print("*" * 50) return db_city
经常会出现卡在commit不动的问题
**************************************************startNone:string_11111add2021-06-24 19:21:35,499 INFO sqlalchemy.engine.Engine INSERT INTO city (province, country, country_code, country_population) VALUES (?, ?, ?, ?)2021-06-24 19:21:35,500 INFO sqlalchemy.engine.Engine [generated in 0.00055s] ('11111', 'string', 'string', 0)2021-06-24 19:21:35,556 INFO sqlalchemy.engine.Engine COMMITWARNING: WatchGodReload detected file change in '['E:\\MyCode\\Python\\FastAPITest\\coronavirus.sqlite3-journal']'. Reloading...WARNING: WatchGodReload detected file change in '['E:\\MyCode\\Python\\FastAPITest\\coronavirus.sqlite3-journal']'. Reloading...2021-06-24 19:21:40,088 INFO sqlalchemy.engine.Engine BEGIN (implicit)2021-06-24 19:21:40,088 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("city")2021-06-24 19:21:40,088 INFO sqlalchemy.engine.Engine [raw sql] ()2021-06-24 19:21:40,095 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("data")2021-06-24 19:21:40,095 INFO sqlalchemy.engine.Engine [raw sql] ()2021-06-24 19:21:40,099 INFO sqlalchemy.engine.Engine COMMITINFO: Started server process [12736]INFO: Waiting for application startup.INFO: Application startup complete.
可以贴一下 database.py, models - > City 类, schema -> CreatedCity 类, curd -> create_city 函数
这四个部分的代码, 感觉可能是哪个环节没有对上. 另外 sqlalchemy 版本是? 我这里比较新的 1.14 版本和教程里的一些操作不兼容
高性能 FastAPI 框架入门精讲
12446 学习 · 87 问题
相似问题