Skip to content

Instantly share code, notes, and snippets.

@premchalmeti
Last active October 17, 2022 23:12
Show Gist options
  • Save premchalmeti/6aa70c12103025645542a481e6f55a07 to your computer and use it in GitHub Desktop.
Save premchalmeti/6aa70c12103025645542a481e6f55a07 to your computer and use it in GitHub Desktop.
SQLAlchemy delete all tables data
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