There is one problem in the previous answer: if you use more than one database, you can accidentally drop tables from the wrong database if you make a "cut and paste" error. Example -
for table_name in db_one.tables(): db_two[table_name].drop()
If you copy code from one model or application to another, itβs too easy to edit a link to db and not another. If db_two has tables with names corresponding to some tables in db_one, you may delete the table in the wrong database. Itβs better to write a trivial function that takes db as a parameter -
def dropdb(thedb): for table_name in thedb.tables(): thedb[table_name].drop()
"Do not repeat yourself."
source share