Column Modifiers
When creating a column from the Blueprint object, a Column object is returned. This column gives you access to a few modifier commands to further configure the column.
comment
Attach a comment to the column.
comment
string
true
The comment text.
Example:
SchemaBuilder
schema.create( "users", function( table ) {
table.integer( "age" ).comment( "Do not lie about your age" );
} );SQL (MySQL)
CREATE TABLE `users` (
`age` INTEGER NOT NULL COMMENT `Do not lie about your age`
)default
Sets a default value for the column.
Note: The value is not escaped, allowing you to specify functions like NOW() or literals like 1. To specify a literal string, wrap the value in quotes.
value
string
true
The default value.
Example:
SchemaBuilder
SQL (MySQL)
nullable
Sets the column to allow null values.
No arguments
All columns are created as NOT NULL by default. As such, there is no notNull method.
Example:
SchemaBuilder
SQL (MySQL)
primaryKey
Adds the column as a primary key for the table.
indexName
string
false
A derived name built from the table name and column name.
The name to use for the primary key constraint.
The primaryKey method returns a TableIndex instance. Additional methods can be chained off of it.
Example:
SchemaBuilder
SQL (MySQL)
references
Creates a foreign key constraint for the column.
value
string
true
The default value.
IMPORTANT: Additional configuration of the foreign constraint is done by calling methods on the returned TableIndex instance.
Example:
SchemaBuilder
SQL (MySQL)
unsigned
Sets the column as unsigned.
No arguments
Example:
SchemaBuilder
SQL (MySQL)
unique
Sets the column to have the UNIQUE constraint.
No arguments
Example:
SchemaBuilder
SQL (MySQL)
withCurrent
Sets the column to have the a default value of CURRENT_TIMESTAMP.
No arguments
Example:
SchemaBuilder
SQL (Postgres)
storedAs
Creates a stored computed column. Computed columns are defined as expressions between other columns and/or constant values. Stored computed columns are saved in the database to avoid computing on every query.
expression
string
true
The SQL used to define the computed column.
virtualAs
Creates a virtual computed column. Computed columns are defined as expressions between other columns and/or constant values. Virtual computed columns are computed on every query.
expression
string
true
The SQL used to define the computed column.
Last updated
Was this helpful?