Migrator
char()
Signature
Section titled “Signature”char() — returns any
Available in: tabledefinition
Category: Table Definition Functions
Description
Section titled “Description”adds char columns to table definition
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
columnNames | string | no | — | |
limit | any | no | — | |
default | any | no | — | |
allowNull | boolean | no | — |
Examples
Section titled “Examples”// 1. Add a single char column to a new table
t = createTable(name='countries');
t.char(columnNames='code', limit=2, allowNull=false);
t.string(columnNames='name', limit=100, allowNull=false);
t.timestamps();
t.create();
// 2. Add multiple char columns at once
t = createTable(name='products');
t.char(columnNames='sku,barcode', limit=12, allowNull=false);
t.string(columnNames='title', limit=255, allowNull=false);
t.timestamps();
t.create();
// 3. Add a char column with a default value when altering an existing table
t = changeTable(name='orders');
t.char(columnNames='statusCode', limit=1, default='N', allowNull=false);
t.change();