Skip to content

Migrator

addColumn()

addColumn() — returns void

Available in: migration Category: Migration Functions

adds a column to existing table Only available in a migration CFC

NameTypeRequiredDefaultDescription
tablestringyes—The Name of the table to add the column to
columnTypestringyes—The type of the new column
columnNamestringno—The name of the new column
columnNamesstringno—Modern alias for columnName (matches the plural form every TableDefinition column helper accepts). Pass one or the other — not both.
afterColumnstringno—The name of the column which this column should be inserted after
referenceNamestringno—Name for new reference column, see documentation for references function, required if columnType is ‘reference’
defaultanyno—Default value for this column
allowNullbooleanno—Whether to allow NULL values
limitnumericno—Character or integer size limit for column
precisionnumericno—precision value for decimal columns, i.e. number of digits the column can hold
scalenumericno—scale value for decimal columns, i.e. number of digits that can be placed to the right of the decimal point (must be less than or equal to precision)
// 1. Add a simple string column to an existing table
addColumn(table="members", columnType="string", columnName="status", limit=50);

// 2. Add a boolean column with a default value and no NULLs allowed
addColumn(
    table="members",
    columnType="boolean",
    columnName="isActive",
    default=1,
    allowNull=false
);

// 3. Add a decimal column with precision and scale (e.g. for a price field)
addColumn(
    table="products",
    columnType="decimal",
    columnName="price",
    precision=10,
    scale=2,
    default=0,
    allowNull=false
);