0

I have a flask application with a background process I have spawned away from the GUI. I have a db session created in association with the Flask app. Because I want to have the freedom to write tables to the db that are not necessarily to be referenced by GUI code, I am not creating the overhead of a class.

The code that creates a table is as follows:

admin_df.to_sql(df_name, con=db.engine, if_exists="replace")

How would I now delete this table?

C. Cooney
  • 471
  • 5
  • 19

1 Answers1

0

The answer I needed is based upon Levon's reply at:

How to delete a table in SQLAlchemy?

Basically, this did the trick:

from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base
from [code location] import db

Base = declarative_base()
metadata = MetaData(db.engine, reflect=True)
table = metadata.tables.get(table_name)
table_to_delete = metadata.tables.get('table_name_for_table_to_delete')
Base.metadata.drop_all(db.engine, [table_to_delete])
C. Cooney
  • 471
  • 5
  • 19