Text 13 Nov dropping all tables on postgres using flask-sqlalchemy

Archiving this so I don’t forget it: in Flask-SQLAlchemy on a Postgres DB, db.drop_all() can fail silently. This can be somewhat infuriating.

This link sums up the situation pretty well. There are a bunch of hacky fixes floating around Google, none of which work, except for a particularly simple one which Mike Bayer himself proposes in the comments of that same link:

db.reflect()
db.drop_all()

db.reflect() is the secret sauce that makes the drop operation work. Which makes sense, I guess.

The catch is that db.reflect() is 100% broken in the current version of Flask-SQLAlchemy. Hopefully that gets fixed soon. In any case, if anyone else is living in a world where db.drop_all() doesn’t drop any of their tables: call db.reflect() first.


Design crafted by Prashanth Kamalakanthan. Powered by Tumblr.