# ColumnSchemaBuilder

> ColumnSchemaBuilder is the schema builder for MySQL databases.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [mysql](/docs/api/yii/db/mysql/index.md) › ColumnSchemaBuilder

| class | `yii\db\mysql\ColumnSchemaBuilder` |
| --- | --- |
| Extends | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`Stringable`](https://www.php.net/manual/en/class.stringable.php), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0.8 |
| Source | [`framework/db/mysql/ColumnSchemaBuilder.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/mysql/ColumnSchemaBuilder.php#L19) |

ColumnSchemaBuilder is the schema builder for MySQL databases.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-categoryMap"></span>[`$categoryMap`](/docs/api/yii/db/columnschemabuilder/index.md#property-categoryMap) | `array` | Mapping of abstract column types (keys) to type categories (values). | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-comment"></span>[`$comment`](/docs/api/yii/db/columnschemabuilder/index.md#property-comment) | `string` | Comment value of the column. Default: `null`. Available since 2.0.8. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-db"></span>[`$db`](/docs/api/yii/db/columnschemabuilder/index.md#property-db) | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md) | The current database connection. Default: `null`. Available since 2.0.8. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-typeCategoryMap"></span>[`$typeCategoryMap`](/docs/api/yii/db/columnschemabuilder/index.md#property-typeCategoryMap) static | `array` | Mapping of abstract column types (keys) to type categories (values). Default: `[\yii\db\Schema::TYPE_PK => self::CATEGORY_PK, \yii\db\Schema::TYPE_UPK => self::CATEGORY_PK, \yii\db\Schema::TYPE_BIGPK => self::CATEGORY_PK, \yii\db\Schema::TYPE_UBIGPK => self::CATEGORY_PK, \yii\db\Schema::TYPE_CHAR => self::CATEGORY_STRING, \yii\db\Schema::TYPE_STRING => self::CATEGORY_STRING, \yii\db\Schema::TYPE_TEXT => self::CATEGORY_STRING, \yii\db\Schema::TYPE_TINYINT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_SMALLINT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_INTEGER => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_BIGINT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_FLOAT => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_DOUBLE => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_DECIMAL => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_DATETIME => self::CATEGORY_TIME, \yii\db\Schema::TYPE_TIMESTAMP => self::CATEGORY_TIME, \yii\db\Schema::TYPE_TIME => self::CATEGORY_TIME, \yii\db\Schema::TYPE_DATE => self::CATEGORY_TIME, \yii\db\Schema::TYPE_BINARY => self::CATEGORY_OTHER, \yii\db\Schema::TYPE_BOOLEAN => self::CATEGORY_NUMERIC, \yii\db\Schema::TYPE_MONEY => self::CATEGORY_NUMERIC]`. Available since 2.0.43. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-typeDefinition"></span>[`$typeDefinition`](/docs/api/yii/db/columnschemabuilder/index.md#property-typeDefinition) read-only | `string` | Abstract type plus optional length, for example `string(255)`. Available since 22.0. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-after"></span>[`$after`](/docs/api/yii/db/columnschemabuilder/index.md#property-after) protected | `string` | The column after which this column will be added. Default: `null`. Available since 2.0.8. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-append"></span>[`$append`](/docs/api/yii/db/columnschemabuilder/index.md#property-append) protected | `mixed` | SQL string to be appended to column schema definition. Default: `null`. Available since 2.0.9. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-check"></span>[`$check`](/docs/api/yii/db/columnschemabuilder/index.md#property-check) protected | `string` | The `CHECK` constraint for the column. Default: `null`. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-default"></span>[`$default`](/docs/api/yii/db/columnschemabuilder/index.md#property-default) protected | `mixed` | Default value of the column. Default: `null`. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-isFirst"></span>[`$isFirst`](/docs/api/yii/db/columnschemabuilder/index.md#property-isFirst) protected | `bool` | Whether this column is to be inserted at the beginning of the table. Default: `null`. Available since 2.0.8. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-isNotNull"></span>[`$isNotNull`](/docs/api/yii/db/columnschemabuilder/index.md#property-isNotNull) protected | `bool\|null` | Whether the column is or not nullable. Default: `null`. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-isUnique"></span>[`$isUnique`](/docs/api/yii/db/columnschemabuilder/index.md#property-isUnique) protected | `bool` | Whether the column values should be unique. Default: `false`. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-isUnsigned"></span>[`$isUnsigned`](/docs/api/yii/db/columnschemabuilder/index.md#property-isUnsigned) protected | `bool` | Whether the column values should be unsigned. Default: `false`. Available since 2.0.7. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-length"></span>[`$length`](/docs/api/yii/db/columnschemabuilder/index.md#property-length) protected | `int\|string\|array` | Column size or precision definition. Default: `null`. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="property-type"></span>[`$type`](/docs/api/yii/db/columnschemabuilder/index.md#property-type) protected | `string` | The column type definition such as INTEGER, VARCHAR, DATETIME, etc. Default: `null`. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/db/columnschemabuilder/index.md#method-__construct) | Create a column schema builder instance giving the type and value precision. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`__toString()`](#method-__toString) | Builds the full string for the column's schema. | `ColumnSchemaBuilder` |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-after"></span>[`after()`](/docs/api/yii/db/columnschemabuilder/index.md#method-after) | Adds an `AFTER` constraint to the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-append"></span>[`append()`](/docs/api/yii/db/columnschemabuilder/index.md#method-append) | Specify additional SQL to be appended to column definition. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-check"></span>[`check()`](/docs/api/yii/db/columnschemabuilder/index.md#method-check) | Sets a `CHECK` constraint for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-comment"></span>[`comment()`](/docs/api/yii/db/columnschemabuilder/index.md#method-comment) | Specifies the comment for column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-defaultExpression"></span>[`defaultExpression()`](/docs/api/yii/db/columnschemabuilder/index.md#method-defaultExpression) | Specify the default SQL expression for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-defaultValue"></span>[`defaultValue()`](/docs/api/yii/db/columnschemabuilder/index.md#method-defaultValue) | Specify the default value for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-first"></span>[`first()`](/docs/api/yii/db/columnschemabuilder/index.md#method-first) | Adds an `FIRST` constraint to the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-getAppend"></span>[`getAppend()`](/docs/api/yii/db/columnschemabuilder/index.md#method-getAppend) | Returns the raw SQL fragment appended to the column definition. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-getCategoryMap"></span>[`getCategoryMap()`](/docs/api/yii/db/columnschemabuilder/index.md#method-getCategoryMap) |  | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-getCheck"></span>[`getCheck()`](/docs/api/yii/db/columnschemabuilder/index.md#method-getCheck) | Returns the raw `CHECK` constraint expression of the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-getDefault"></span>[`getDefault()`](/docs/api/yii/db/columnschemabuilder/index.md#method-getDefault) | Returns the raw default value of the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-getTypeDefinition"></span>[`getTypeDefinition()`](/docs/api/yii/db/columnschemabuilder/index.md#method-getTypeDefinition) | Returns the abstract type together with its length or precision, without any constraint keywords. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-isNotNull"></span>[`isNotNull()`](/docs/api/yii/db/columnschemabuilder/index.md#method-isNotNull) | Returns the nullability state of the column as a tri-state value. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-isUnique"></span>[`isUnique()`](/docs/api/yii/db/columnschemabuilder/index.md#method-isUnique) | Returns whether the column carries a `UNIQUE` constraint. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-notNull"></span>[`notNull()`](/docs/api/yii/db/columnschemabuilder/index.md#method-notNull) | Adds a `NOT NULL` constraint to the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-null"></span>[`null()`](/docs/api/yii/db/columnschemabuilder/index.md#method-null) | Adds a `NULL` constraint to the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-setCategoryMap"></span>[`setCategoryMap()`](/docs/api/yii/db/columnschemabuilder/index.md#method-setCategoryMap) |  | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-unique"></span>[`unique()`](/docs/api/yii/db/columnschemabuilder/index.md#method-unique) | Adds a `UNIQUE` constraint to the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-unsigned"></span>[`unsigned()`](/docs/api/yii/db/columnschemabuilder/index.md#method-unsigned) | Marks column as unsigned. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| [`buildAfterString()`](#method-buildAfterString) protected | Builds the after constraint for the column. Defaults to unsupported. | `ColumnSchemaBuilder` |
| <span id="method-buildAppendString"></span>[`buildAppendString()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildAppendString) protected | Builds the custom string that's appended to column definition. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-buildCheckString"></span>[`buildCheckString()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildCheckString) protected | Builds the check constraint for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| [`buildCommentString()`](#method-buildCommentString) protected | Builds the comment specification for the column. | `ColumnSchemaBuilder` |
| <span id="method-buildCompleteString"></span>[`buildCompleteString()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildCompleteString) protected | Returns the complete column definition from input format. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-buildDefaultString"></span>[`buildDefaultString()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildDefaultString) protected | Builds the default value specification for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-buildDefaultValue"></span>[`buildDefaultValue()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildDefaultValue) protected | Return the default value for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| [`buildFirstString()`](#method-buildFirstString) protected | Builds the first constraint for the column. Defaults to unsupported. | `ColumnSchemaBuilder` |
| <span id="method-buildLengthString"></span>[`buildLengthString()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildLengthString) protected | Builds the length/precision part of the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-buildNotNullString"></span>[`buildNotNullString()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildNotNullString) protected | Builds the not null constraint for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="method-buildUniqueString"></span>[`buildUniqueString()`](/docs/api/yii/db/columnschemabuilder/index.md#method-buildUniqueString) protected | Builds the unique constraint for the column. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| [`buildUnsignedString()`](#method-buildUnsignedString) protected | Builds the unsigned string for column. Defaults to unsupported. | `ColumnSchemaBuilder` |
| <span id="method-getTypeCategory"></span>[`getTypeCategory()`](/docs/api/yii/db/columnschemabuilder/index.md#method-getTypeCategory) protected | Returns the category of the column type. | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-CATEGORY_PK"></span>[`CATEGORY_PK`](/docs/api/yii/db/columnschemabuilder/index.md#const-CATEGORY_PK) | `'pk'` |  | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="const-CATEGORY_STRING"></span>[`CATEGORY_STRING`](/docs/api/yii/db/columnschemabuilder/index.md#const-CATEGORY_STRING) | `'string'` |  | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="const-CATEGORY_NUMERIC"></span>[`CATEGORY_NUMERIC`](/docs/api/yii/db/columnschemabuilder/index.md#const-CATEGORY_NUMERIC) | `'numeric'` |  | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="const-CATEGORY_TIME"></span>[`CATEGORY_TIME`](/docs/api/yii/db/columnschemabuilder/index.md#const-CATEGORY_TIME) | `'time'` |  | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |
| <span id="const-CATEGORY_OTHER"></span>[`CATEGORY_OTHER`](/docs/api/yii/db/columnschemabuilder/index.md#const-CATEGORY_OTHER) | `'other'` |  | [`yii\db\ColumnSchemaBuilder`](/docs/api/yii/db/columnschemabuilder/index.md) |

## Method details

### __toString() <span id="method-__toString"></span>

```php
public function __toString(): string
```

Builds the full string for the column's schema.

**Returns**

`string`

### buildAfterString() <span id="method-buildAfterString"></span>

```php
protected function buildAfterString(): string
```

Builds the after constraint for the column. Defaults to unsupported.

**Returns**

`string`: A string containing the AFTER constraint.

**Since**

2.0.8

### buildCommentString() <span id="method-buildCommentString"></span>

```php
protected function buildCommentString(): string
```

Builds the comment specification for the column.

**Returns**

`string`: A string containing the COMMENT keyword and the comment itself

**Since**

2.0.8

### buildFirstString() <span id="method-buildFirstString"></span>

```php
protected function buildFirstString(): string
```

Builds the first constraint for the column. Defaults to unsupported.

**Returns**

`string`: A string containing the FIRST constraint.

**Since**

2.0.8

### buildUnsignedString() <span id="method-buildUnsignedString"></span>

```php
protected function buildUnsignedString(): string
```

Builds the unsigned string for column. Defaults to unsupported.

**Returns**

`string`: A string containing UNSIGNED keyword.

**Since**

2.0.7