Skip to content

Instantly share code, notes, and snippets.

@rahman541
Created August 11, 2018 20:04
Show Gist options
  • Save rahman541/f37b62cc842e32dcc96440894fac9b12 to your computer and use it in GitHub Desktop.
Save rahman541/f37b62cc842e32dcc96440894fac9b12 to your computer and use it in GitHub Desktop.
*UPDATED*: How to drop all tables from database using Yii2. Includes disabling foreign key checks, fixed app() and execute().
<?php
Yii::$app->db->createCommand("SET foreign_key_checks = 0")->execute();
$tables = Yii::$app->db->schema->getTableNames();
foreach ($tables as $table) {
Yii::$app->db->createCommand()->dropTable($table)->execute();
}
Yii::$app->db->createCommand("SET foreign_key_checks = 1")->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment