Migrator
text()
Signature
Section titled “Signature”text() — returns any
Available in: tabledefinition
Category: Table Definition Functions
Description
Section titled “Description”Adds text columns to table definition. In MySQL databases, you can specify different text sizes:
- Regular TEXT (65KB) - default when no size is specified
- MEDIUMTEXT (16MB) - specify size=“mediumtext”
- LONGTEXT (4GB) - specify size=“longtext” For other database engines, the size parameter is ignored and the default text type is used.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
columnNames | string | no | — | |
default | any | no | — | |
allowNull | boolean | no | — | |
size | string | no | — |
Examples
Section titled “Examples”// 1. Add a single text column to a table
t.text("body");
// 2. Add multiple text columns at once
t.text("summary,description,notes");
// 3. Add a text column that defaults to an empty string and disallows nulls
t.text(columnNames="bio", default="", allowNull=false);
// 4. Add a MEDIUMTEXT column in MySQL (16MB capacity; ignored on other databases)
t.text(columnNames="content", size="mediumtext");
// 5. Add a LONGTEXT column in MySQL (4GB capacity; ignored on other databases)
t.text(columnNames="rawHtml", size="longtext");
// 6. Full migration example using text() inside createTable
t = createTable("articles");
t.string("title");
t.text("body");
t.text(columnNames="excerpt", allowNull=true);
t.timestamps();
t.create();