Last active
October 17, 2022 23:12
-
-
Save premchalmeti/6aa70c12103025645542a481e6f55a07 to your computer and use it in GitHub Desktop.
SQLAlchemy delete all tables data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session = Session() | |
# Explicitly mention the tables having foreign key then concrete classes. | |
tables = [UserEmail, UserPermission, User, GroupPermission, Permission, Role, GroupMember, Group] | |
for table in tables: | |
session.query(table).delete() | |
session.commit() | |
print(table, 'data deleted') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment