How to create all tables defined in models using peewee

前端 未结 6 1673
小鲜肉
小鲜肉 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:57

    An update for Python 3 (and everyone who comes across this question via Google like I did). If you have all models based on the main peewee Model class you can simply use:

    import peewee    
    models = peewee.Model.__subclasses__()
    

    Credit to this question for the idea. They also go into more detail on how to get it to work recursively if your model is more complex.

提交回复
热议问题