code: protected function truncateDatabase()
      {
          $db = $this->db;
          $schemas = $db->schema->getTableSchemas();
  
          // First drop all foreign keys,
          foreach ($schemas as $schema) {
              if ($schema->foreignKeys) {
                  foreach ($schema->foreignKeys as $name => $foreignKey) {
                      $db->createCommand()->dropForeignKey($name, $schema->name)->execute();
                      $this->stdout("Foreign key $name dropped.\n");
                  }
              }
          }
  
          // Then drop the tables:
          foreach ($schemas as $schema) {
              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");
                  }
              }
          }
      }
docs: {@inheritdoc}
  @since 2.0.13