Make sure tables exist before we try to delete them

This commit is contained in:
mike cullerton 2021-08-06 09:50:57 -04:00
parent 6e1fedb704
commit 70f391d612
1 changed files with 4 additions and 1 deletions

View File

@ -16,8 +16,11 @@ class ExampleDataLoader:
@staticmethod
def clean_db():
session.flush() # Clear out any transactions before deleting it all to avoid spurious errors.
engine = session.bind.engine
connection = engine.connect()
for table in reversed(db.metadata.sorted_tables):
session.execute(table.delete())
if engine.dialect.has_table(connection, table):
session.execute(table.delete())
session.commit()
session.flush()