yii\db\Schema::refreshTableSchema PHP Method

refreshTableSchema() public method

This method cleans up cached table schema so that it can be re-created later to reflect the database schema change.
Since: 2.0.6
public refreshTableSchema ( string $name )
$name string table name.
    public function refreshTableSchema($name)
    {
        unset($this->_tables[$name]);
        $this->_tableNames = [];
        /* @var $cache Cache */
        $cache = is_string($this->db->schemaCache) ? Yii::$app->get($this->db->schemaCache, false) : $this->db->schemaCache;
        if ($this->db->enableSchemaCache && $cache instanceof Cache) {
            $cache->delete($this->getCacheKey($name));
        }
    }

Usage Example

Example #1
0
 /**
  * Refreshes the particular table schema.
  * This method cleans up cached table schema so that it can be re-created later
  * to reflect the database schema change.
  * @param string $name table name.
  * @since 2.0.6
  */
 public function refreshTableSchema($name)
 {
     try {
         $sql = "CALL ADMIN_CMD ('REORG TABLE " . $this->db->quoteTableName($name) . "')";
         $this->db->createCommand($sql)->execute();
     } catch (\Exception $ex) {
         // Do not throw error on table which doesn't exist
         if (!(isset($ex->errorInfo[1]) && $ex->errorInfo[1] === -2211)) {
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
         }
     }
     parent::refreshTableSchema($name);
 }