Builds and executes a SQL statement for dropping a DB column.
public dropColumn ( string $table, string $column ) | ||
$table | string | the table whose column is to be dropped. The name will be properly quoted by the method. |
$column | string | the name of the column to be dropped. The name will be properly quoted by the method. |
/** * Drop multiple columns to a table * @param string $table * @param array $columns ["column_name"=>type] */ public function dropColumns($table, $columns) { foreach ($columns as $column => $type) { parent::dropColumn($table, $column); } }
/** * @throws \yii\base\NotSupportedException */ public function afterDelete() { parent::afterDelete(); $cm = $this->cm; $mg = new Migration(); $table = Cm::$TAB_PREFIX[$cm->tab_index] . $cm->tab; $tableSchema = $mg->db->getSchema()->getTableSchema('{{%' . $table . '}}'); if ($tableSchema === null) { return; } $columns = $tableSchema->getColumnNames(); if (in_array($this->name, $columns)) { $mg->dropColumn('{{%' . $table . '}}', $this->name); } }
/** * @inheritdoc * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true. */ public function dropColumn($table, $column) { $table = $this->autoWrappedTableName($table); return parent::dropColumn($table, $column); }
public function dropColumn($table, $column, $type = null) { if ($type instanceof ForeignKeyColumn) { $type->migrate = $this; $type->sourceTable($table); $type->sourceColumn($column); $type->remove(); } return parent::dropColumn($table, $column); }