我正在嘗試在某個路徑上創建一個資料庫,但我不知道該怎么做,因為我需要在 Meta 中參考創建的資料庫
我正在嘗試創建這樣的資料庫:
class Domain(Model):
...
class Meta:
database = db
...
def create_database(path: str, start_block: int):
db = SqliteDatabase(os.path.join(path, "db"))
db.create_tables([Domain, Event, State])
if State.select().count() == 0:
State.create(height=start_block)
uj5u.com熱心網友回復:
這在檔案中有所介紹:
- http://docs.peewee-orm.com/en/latest/peewee/database.html#run-time-database-configuration
- http://docs.peewee-orm.com/en/latest/peewee/database.html#dynamically-defining-a-database
- http://docs.peewee-orm.com/en/latest/peewee/database.html#setting-the-database-at-run-time
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/490805.html
上一篇:多個子查詢和視窗操作SQLite
