How to create all tables defined in models using peewee

前端 未结 6 1567
小鲜肉
小鲜肉 2021-02-20 08:07

I define a lot of model classes using peewee. ClassName.create_table() can generate the table,but only one table. How could I create all tables using a single state

6条回答
  •  不思量自难忘°
    2021-02-20 08:55

    Peewee has a helper that will create the tables in the correct order, but you still need to explicitly pass in all the models:

    from peewee import *
    db = SqliteDatabase(':memory:')
    db.create_tables([ModelA, ModelB, ModelC])
    

提交回复
热议问题