Reputation: 2025
How can I check if a database is empty in SQLAlchemy?
I know you can do inspector.dialect.has_table(engine.connect(), 'table_name')
to check for the existence of a single table, but I want to know if there are any tables at all in the database.
Upvotes: 0
Views: 1137
Reputation: 2340
You can check tables in current database:
db.engine.table_names()
or after creating engine
variable from connection string:
engine = sql.create_engine("connection_string")
sql.inspect(engine).get_table_names()
Upvotes: 1