def truncate_table(self, table, disable_foreign_key_checks=False): """Truncate a table from the database Raises an error if the table does not exists Parameters ---------- table: string Name of the table to truncate. disable_foreign_key_checks: boolean Flag indicating whether foreign keys shall be checked Returns ------- None """ Assert.py_type(table, str, 'table') Assert.table_exists(table, self) if disable_foreign_key_checks: # Temporarily disable foreign key checks sql = '''SET FOREIGN_KEY_CHECKS = 0''' self.execute(sql) truncate = 'TRUNCATE {}'.format(table) self.execute(truncate) if disable_foreign_key_checks: # Reenable foreign key checks sql = '''SET FOREIGN_KEY_CHECKS = 1''' self.execute(sql)