Last active
December 20, 2015 12:09
-
-
Save rfinz/6128686 to your computer and use it in GitHub Desktop.
Snippet that initializes a DB with all the tables defined in a peewee ORM model... in this case "MariaModel". Add tables to the model at any point and the program should be able to set up the DB programmatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for t in [ name for name,c in \ | |
inspect.getmembers(sys.modules[__name__],inspect.isclass) \ | |
if issubclass(c, MariaModel) and not c is MariaModel]: | |
try: | |
globals()[t].create_table() | |
except Exception as e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only downside is that it doesn't ensure hierarchical creation of the tables and therefore foreign key enforcement.