table.fieldAdd
Adds a field to one of the model's tables.
TIP
For more control, such as other column types, indexes or keys, manage tables with SQL instead. Run CREATE, ALTER and DROP TABLE statements with DatasourceClient's execute.
js
table.fieldAdd(tableName, fieldName, fieldType)Parameters
| Parameter | Type | Description |
|---|---|---|
tableName | string | The table's name or id. |
fieldName | string | The new field's name. |
fieldType | string | The field's type, from Field types. |
Returns
booleantrue if the field was added, otherwise false. The reason is written to the process log.
Field types
The type names aren't case-sensitive, but must otherwise match exactly.
| Type | MySQL type |
|---|---|
CALCULATED NUMERIC | DECIMAL(15,5) |
CALCULATED TEXT | VARCHAR(512) |
DATE | DATE |
DATE TIME | TIMESTAMP |
DATE TIME CREATED | TIMESTAMP, defaulting to the current time |
DATE TIME LAST UPDATED | TIMESTAMP |
FILE ATTACHMENT | MEDIUMTEXT |
NUMERIC | DECIMAL(15,5) |
REMOTE IDENTIFIER | INT(11) |
TEXT [25,000] | TEXT(25000) |
TEXT FORMATTED [25,000] | TEXT(25000) |
TEXT [512] | VARCHAR(512) |
TEXT [55] | VARCHAR(55) |
TEXT [LIST] | VARCHAR(512) |
TIME | TIME |
UNIQUE IDENTIFIER | INT, auto-incrementing |
USER ID CREATOR | INT(11) |
USER ID LAST MODIFIED | INT(11) |
USER ID | INT(11) |
YES OR NO | TINYINT(1) |
Examples
js
const created = table.fieldAdd("users", "password", "Text [512]");