Fixes #16278: Fixed drop existing views when console migrate/fresh command runs

This commit is contained in:
Elvira Sheina
2018-06-30 04:19:40 +05:00
committed by Alexander Makarov
parent 77d7a5046e
commit e55b3e0ba1
3 changed files with 16 additions and 2 deletions

View File

@ -310,8 +310,17 @@ class MigrateController extends BaseMigrateController
// Then drop the tables:
foreach ($schemas as $schema) {
$db->createCommand()->dropTable($schema->name)->execute();
$this->stdout("Table {$schema->name} dropped.\n");
try {
$db->createCommand()->dropTable($schema->name)->execute();
$this->stdout("Table {$schema->name} dropped.\n");
} catch (\Exception $e) {
if (strpos($e->getMessage(), 'DROP VIEW to delete view') !== false) {
$db->createCommand()->dropView($schema->name)->execute();
$this->stdout("View {$schema->name} dropped.\n");
} else {
$this->stdout("Cannot drop {$schema->name} Table .\n");
}
}
}
}