9.2.0
Search
K

Columns

The Blueprint object has many column types available to construct your table schema. Additionally, you can modify the columns created with an additional set of methods and indexes.

bigIncrements

Create an auto-incrementing column using an unsigned BIGINT type. This column is also set as the primary key for the table.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
indexName
string
false
The name for the primary key index. If no name is passed in, the name will be dynamically created based off of the table name and column name.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.bigIncrements( "id" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
CONSTRAINT `pk_users_id` PRIMARY KEY (`id`)
)

bigInteger

Create a column using a BIGINT equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
precision
numeric
false
The precision for the column.
Example (no precision):
SchemaBuilder
schema.create( "users", function( table ) {
table.bigInteger( "salary" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`salary` BIGINT NOT NULL
)
Example (with precision):
SchemaBuilder
schema.create( "users", function( table ) {
table.bigInteger( "salary", 5 );
} );
SQL (MySQL)
CREATE TABLE `users` (
`salary` BIGINT(5) NOT NULL
)

bit

Create a column using a BIT equivalent type for your database. The length can be specified as the second argument.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
length
numeric
false
1
The length for the column.
Example (default length):
SchemaBuilder
schema.create( "users", function( table ) {
table.bit( "is_active" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`is_active` BIT(1) NOT NULL
)
Example (custom length):
SchemaBuilder
schema.create( "users", function( table ) {
table.bit( "is_active", 2 );
} );
SQL (MySQL)
CREATE TABLE `users` (
`is_active` BIT(2) NOT NULL
)

boolean

Create a column using a BOOLEAN equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.boolean( "is_subscribed" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`is_subscribed` TINYINT(1) NOT NULL
)

char

Create a column using a CHAR equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
length
numeric
false
1
The length for the column.
Example (default length):
SchemaBuilder
schema.create( "students", function( table ) {
table.char( "grade" );
} );
SQL (MySQL)
CREATE TABLE `students` (
`grade` CHAR(1) NOT NULL
)
Example (custom length):
SchemaBuilder
schema.create( "users", function( table ) {
table.char( "tshirt_size", 4 );
} );
SQL (MySQL)
CREATE TABLE `users` (
`tshirt_size` CHAR(4) NOT NULL
)

date

Create a column using a DATE equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.date( "birthday" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`birthday` DATE NOT NULL
)

datetime

Create a column using a DATETIME equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.datetime( "hire_date" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`hire_date` DATETIME NOT NULL
)

datetimeTz

Create a column using a timezone-specific DATETIME equivalent type for your database.
Some databases do not have the concept of a timezone-specific datetime. Those databases will use a normal DATETIME type.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "posts", function( table ) {
table.datetimeTz( "posted_date" );
} );
SQL (SQL Server)
CREATE TABLE [posts] (
[posted_date] DATETIMEOFFSET NOT NULL
)

decimal

Create a column using a DECIMAL equivalent type for your database. The length and precision can be specified as the second and third arguments.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
length
numeric
false
10
The length of the column.
precision
numeric
false
0
The precision of the column.
Example (with defaults):
SchemaBuilder
schema.create( "weather", function( table ) {
table.decimal( "temperature" );
} );
SQL (MySQL)
CREATE TABLE `weather` (
`temperature` DECIMAL(10,0) NOT NULL
)
Example (with length):
SchemaBuilder
schema.create( "weather", function( table ) {
table.decimal( "temperature", 4 );
} );
SQL (MySQL)
CREATE TABLE `weather` (
`temperature` DECIMAL(4,0) NOT NULL
)
Example (with precision):
SchemaBuilder
schema.create( "weather", function( table ) {
table.decimal( name = "temperature", precision = 2 );
} );
SQL (MySQL)
CREATE TABLE `weather` (
`temperature` DECIMAL(10,2) NOT NULL
)

enum

Create a column using a ENUM equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.enum( "tshirt_size", [ "S", "M", "L", "XL", "XXL" ] );
} );
SQL (MySQL)
CREATE TABLE `users` (
`tshirt_size` ENUM(`S`, `M`, `L`, `XL`, `XXL`) NOT NULL
)

float

Create a column using a FLOAT equivalent type for your database. The length and precision can be specified as the second and third arguments.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
length
numeric
false
10
The length of the column.
precision
numeric
false
0
The precision of the column.
Example (with defaults):
SchemaBuilder
schema.create( "weather", function( table ) {
table.float( "temperature" );
} );
SQL (MySQL)
CREATE TABLE `weather` (
`temperature` FLOAT(10,0) NOT NULL
)
Example (with length):
SchemaBuilder
schema.create( "weather", function( table ) {
table.float( "temperature", 4 );
} );
SQL (MySQL)
CREATE TABLE `weather` (
`temperature` FLOAT(4,0) NOT NULL
)
Example (with precision):
SchemaBuilder
schema.create( "weather", function( table ) {
table.float( name = "temperature", precision = 2 );
} );
SQL (MySQL)
CREATE TABLE `weather` (
`temperature` FLOAT(10,2) NOT NULL
)

guid

SQL Server: Create a column using a uniqueidentifier.
MySQL and Others: Create a column using a CHAR equivalent type for your database and a length of 36. Used in conjunction with the Lucee createGUID method or Java's java.util.UUID.randomUUID().
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.guid( "id" ).primaryKey();
} );
MySQL (SQL Server)
CREATE TABLE `games` (
`id` uniqueidentifier NOT NULL,
CONSTRAINT `pk_games_id` PRIMARY KEY (`id`)
)
SQL (MySQL)
CREATE TABLE `games` (
`id` VARCHAR(36) NOT NULL,
CONSTRAINT `pk_games_id` PRIMARY KEY (`id`)
)

increments

Create an auto-incrementing column using an unsigned INTEGER type. This column is also set as the primary key for the table.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
indexName
string
false
The name for the primary key index. If no name is passed in, the name will be dynamically created based off of the table name and column name.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.increments( "id" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
CONSTRAINT `pk_users_id` PRIMARY KEY (`id`)
)

integer

Create a column using a INTEGER equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
precision
numeric
false
The precision for the column.
Example (no precision):
SchemaBuilder
schema.create( "games", function( table ) {
table.integer( "score" );
} );
SQL (MySQL)
CREATE TABLE `games` (
`score` INTEGER NOT NULL
)
Example (with precision):
SchemaBuilder
schema.create( "games", function( table ) {
table.integer( "score", 3 );
} );
SQL (MySQL)
CREATE TABLE `games` (
`score` INTEGER(3) NOT NULL
)

json

Create a column using a JSON equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.json( "options" ).nullable();
} );
SQL (MySQL)
CREATE TABLE `users` (
`options` JSON
)

lineString

Create a column using a LINESTRING equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.lineString( "positions" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`positions` LINESTRING NOT NULL
)

longText

Create a column using a LONGTEXT equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
Example:
SchemaBuilder
schema.create( "posts", function( table ) {
table.longText( "body" );
} );
SQL (MySQL)
CREATE TABLE `posts` (
`body` LONGTEXT NOT NULL
)

mediumIncrements

Create an auto-incrementing column using an unsigned MEDIUMINT type. This column is also set as the primary key for the table.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
indexName
string
false
The name for the primary key index. If no name is passed in, the name will be dynamically created based off of the table name and column name.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.mediumIncrements( "id" );
} );
SQL (MySQL)
CREATE TABLE `users` (
`id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
CONSTRAINT `pk_users_id` PRIMARY KEY (`id`)
)

mediumInteger

Create a column using a MEDIUMINT equivalent type for your database.
Argument
Type
Required
Default
Description
name
string
true
The name for the column.
precision
numeric
false
10
The precision for the column.
Example (no precision):
SchemaBuilder
schema.create( "games", function( table ) {
table.mediumInteger( "score" );
} );
SQL (MySQL)
CREATE TABLE `games` (
`score` MEDIUMINT NOT NULL
)
Example (with precision):
SchemaBuilder
schema.create( "games", function( table ) {
table.mediumInteger( "score", 5 );
} );
SQL (MySQL)
CREATE TABLE `games` (
`score` MEDIUMINT(5) NOT NULL
)