:::: MENU ::::

Magento 2 available install schema columns type

Magento 2 available install schema columns type

Today we talk about Magento 2 available install schema columns type That we can use in install schema that is already mention in my post Magento 2 Create a install Schema. There are different type available in magneto 2. Type of column that you can is listed below with example.

Type boolean

TYPE_BOOLEAN = ‘boolean’;
Boolean: These types are synonyms for TINYINT(1). A value of zero is considered false. Non-zero values are considered true.
Example

addColumn(
            'post_id',
            Table::TYPE_BOOLEAN,
            null,
            [ 'identity' => false, 'nullable' => false, 'primary' => true ],
            'Post ID'
        )

Type smallint

TYPE_SMALLINT = ‘smallint’;
Example

addColumn(
            'post_id',
            Table::TYPE_SMALLINT,
            null,
            [ 'nullable' => false],
            'Post ID'
        )

Type integer

TYPE_INTEGER = ‘integer’;
Example

addColumn(
            'post_id',
            Table::TYPE_INTEGER,
            null,
            ['nullable' => false],
            'Post ID'
        )

Type bigint

TYPE_BIGINT = ‘bigint’;
Example

addColumn(
            'post_id',
            Table::TYPE_BIGINT,
            null,
            [ 'nullable' => false],
            'Post ID'
        )

Type float

TYPE_FLOAT = ‘float’;
Example

addColumn(
            'post_id',
            Table::TYPE_FLOAT,
            null,
            [ 'nullable' => false],
            'Post ID'
        )

Type numeric

TYPE_NUMERIC = ‘numeric’;
Example

addColumn(
            'post_id',
            Table::TYPE_NUMERIC,
            null,
            [ 'nullable' => false],
            'Post ID'
        )

Type decimal

TYPE_DECIMAL = ‘decimal’;
Example

addColumn(
            'post_id',
            Table::TYPE_DECIMAL,
            null,
            [ 'nullable' => false],
            'Post ID'
        )

Type date

TYPE_DATE = ‘date’;
Example

addColumn(
            'data',
            Table::TYPE_DATE,
            null,
            [ 'nullable' => false],
            'Post ID'
        )

Type timestamp

TYPE_TIMESTAMP = ‘timestamp’;
Example

->addColumn(
            'creation_time',
            Table::TYPE_TIMESTAMP,
            null,
            ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
            'Creation Time'
        )

Type datetime

Capable to support date-time from 1970 + auto-triggers in some RDBMS
TYPE_DATETIME = ‘datetime’;
Example

addColumn(
            'data',
            Table::TYPE_DATETIME,
            null,
            [ 'nullable' => false ],
            'Post ID'
        )

Type text

Capable to support long date-time before 1970
TYPE_TEXT = ‘text’;
Example

addColumn(
            'data',
            Table::TYPE_TEXT,
            255,
            [ 'nullable' => false],
            'Post ID'
        )

Type blob

TYPE_BLOB = ‘blob’;
Example

addColumn(
            'data',
            Table::TYPE_BLOB ,
            null,
            [ 'nullable' => false],
            'Post ID'
        )

Type varbinary

Used for back compatibility, when query param can’t use statement options
TYPE_VARBINARY = ‘varbinary’;
Example

addColumn(
            'data',
            Table::TYPE_VARBINARY,
            null,
            [ 'nullable' => false],
            'Post ID'
        )
Author: Qaisar Satti
Category: Magento 2
Last Modified: July 12, 2018


So, what do you think ?