Skip to content

Migrator

changeColumn()

changeColumn() — returns void

Available in: migration Category: Migration Functions

changes a column definition Only available in a migration CFC

NameTypeRequiredDefaultDescription
tablestringyes—The Name of the table where the column is
columnNamestringno—The name of the column
columnNamesstringno—Modern alias for columnName (matches the plural form every TableDefinition column helper accepts). Pass one or the other — not both.
columnTypestringyes—The type of the column
afterColumnstringno—The name of the column which this column should be inserted after
referenceNamestringno—Name for 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—(For decimal type) the maximum number of digits allow
scalenumericno—(For decimal type) the number of digits to the right of the decimal point
addColumnsbooleannofalseif true, attempts to add columns and database will likely throw an error if column already exists
// 1. Change a string column's length limit
changeColumn(table="members", columnName="status", columnType="string", limit=50);

// 2. Change a column type and set a default value
changeColumn(table="orders", columnName="quantity", columnType="integer", default=1);

// 3. Change a decimal column with precision and scale
changeColumn(table="products", columnName="price", columnType="decimal", precision=10, scale=2, allowNull=false);

// 4. Change a text column and explicitly allow NULL values
changeColumn(table="articles", columnName="summary", columnType="text", allowNull=true);