Created
August 11, 2018 20:04
-
-
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().
This file contains 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
<?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