Where should I put the code for checking if a table exists in python if I use peewee
2 answers
From http://peewee.readthedocs.org/en/latest/peewee/api.html#Model.table_exists you can do for example
if Model.table_exists():
do stuff
or if you do it while creating tables - even easier than http://peewee.readthedocs.org/en/latest/peewee/api.html#Model.create_table
Model.create_table(True)
+15
source to share
When I create an application, I usually put the code to create tables at the entry point of the application. For scripting this if __name__ == '__main__':
, for web applications, some kind of main module is usually used that initializes the wsgi application.
http://charlesleifer.com/blog/structuring-flask-apps-a-how-to-for-those-coming-from-django/
0
source to share