Skip to content

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 ​

ParameterTypeDescription
tableNamestringThe table's name or id.
fieldNamestringThe new field's name.
fieldTypestringThe field's type, from Field types.

Returns ​

boolean

true 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.

TypeMySQL type
CALCULATED NUMERICDECIMAL(15,5)
CALCULATED TEXTVARCHAR(512)
DATEDATE
DATE TIMETIMESTAMP
DATE TIME CREATEDTIMESTAMP, defaulting to the current time
DATE TIME LAST UPDATEDTIMESTAMP
FILE ATTACHMENTMEDIUMTEXT
NUMERICDECIMAL(15,5)
REMOTE IDENTIFIERINT(11)
TEXT [25,000]TEXT(25000)
TEXT FORMATTED [25,000]TEXT(25000)
TEXT [512]VARCHAR(512)
TEXT [55]VARCHAR(55)
TEXT [LIST]VARCHAR(512)
TIMETIME
UNIQUE IDENTIFIERINT, auto-incrementing
USER ID CREATORINT(11)
USER ID LAST MODIFIEDINT(11)
USER IDINT(11)
YES OR NOTINYINT(1)

Examples ​

js
const created = table.fieldAdd("users", "password", "Text [512]");