Tony's Blog

Magento 2 available install schema columns type

1. 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

  1. addColumn(
  2. 'post_id',
  3. Table::TYPE_BOOLEAN,
  4. null,
  5. [ 'identity' => false, 'nullable' => false, 'primary' => true ],
  6. 'Post ID'
  7. )

2. Type smallint

TYPE_SMALLINT = ‘smallint’;

Example

  1. addColumn(
  2. 'post_id',
  3. Table::TYPE_SMALLINT,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

3. Type integer

TYPE_INTEGER = ‘integer’;

Example

  1. addColumn(
  2. 'post_id',
  3. Table::TYPE_INTEGER,
  4. null,
  5. ['nullable' => false],
  6. 'Post ID'
  7. )

4. Type bigint

TYPE_BIGINT = ‘bigint’;

Example

  1. addColumn(
  2. 'post_id',
  3. Table::TYPE_BIGINT,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

5. Type float

TYPE_FLOAT = ‘float’;

Example

  1. addColumn(
  2. 'post_id',
  3. Table::TYPE_FLOAT,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

6. Type numeric

TYPE_NUMERIC = ‘numeric’;

Example

  1. addColumn(
  2. 'post_id',
  3. Table::TYPE_NUMERIC,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

7. Type decimal

TYPE_DECIMAL = ‘decimal’;

Example

  1. addColumn(
  2. 'post_id',
  3. Table::TYPE_DECIMAL,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

8. Type date

TYPE_DATE = ‘date’;

Example

  1. addColumn(
  2. 'data',
  3. Table::TYPE_DATE,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

9. Type timestamp

TYPE_TIMESTAMP = ‘timestamp’;

Example

  1. ->addColumn(
  2. 'creation_time',
  3. Table::TYPE_TIMESTAMP,
  4. null,
  5. ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
  6. 'Creation Time'
  7. )

10. Type datetime

Capable to support date-time from 1970 + auto-triggers in some RDBMS

TYPE_DATETIME = ‘datetime’;

Example

  1. addColumn(
  2. 'data',
  3. Table::TYPE_DATETIME,
  4. null,
  5. [ 'nullable' => false ],
  6. 'Post ID'
  7. )

11. Type text

Capable to support long date-time before 1970

TYPE_TEXT = ‘text’;

Example

  1. addColumn(
  2. 'data',
  3. Table::TYPE_TEXT,
  4. 255,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

12. Type blob

TYPE_BLOB = ‘blob’;

Example

  1. addColumn(
  2. 'data',
  3. Table::TYPE_BLOB ,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

13. Type varbinary

Used for back compatibility, when query param can’t use statement options

TYPE_VARBINARY = ‘varbinary’;

Example

  1. addColumn(
  2. 'data',
  3. Table::TYPE_VARBINARY,
  4. null,
  5. [ 'nullable' => false],
  6. 'Post ID'
  7. )

That’s all.