Does anybody know how to clear all DB content with SqlAlchemy in ORM style and without knowing its structure?
Problem that user gives connection details (login, psw, DB name), and we have to prepare installation of our DB structure. So, I want to clear all old data in given DB.
Previous versions of columns might be created without usage of necessary statements (cascade="all, delete") in relationships. Also its structure might be unknown to us. Are there any secure way how to delete whole DB content? I can do this in raw SQL, using DROP TABLE ... CASCADE, but I need an ORM way.
For example these lines throws sqlalchemy.exc.IntegrityError due to absence CASCADE instruction in query:
for tbl in reversed(Base.metadata.sorted_tables):
db.execute(tbl.delete())
and this line throws sqlalchemy.exc.InternalError also due to absence CASCADE instruction in query.
Base.metadata.drop_all(bind=db)
Here a lot of info how to do this, but every solution depends from column relationships, which are unknown to us. Thanks in advance!