How to create all tables defined in models using peewee

Alexander.Li picture Alexander.Li · Feb 7, 2014 · Viewed 7.4k times · Source

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 statement?

Answer

coleifer picture coleifer · Feb 7, 2014

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])