Skip to content

Migrator

renameColumn()

renameColumn() — returns void

Available in: migration Category: Migration Functions

Used to change the name of an existing column in a database table within a migration CFC. This is useful when you need to standardize column names, correct naming mistakes, or improve clarity in your database schema. Renaming a column preserves the existing data and column type while updating the schema. Only available in a migration CFC.

NameTypeRequiredDefaultDescription
tablestringyesThe table containing the column to rename
columnNamestringyesThe column name to rename
newColumnNamestringyesThe new column name
1. Rename a column in the users table
renameColumn(table="users", columnName="username", newColumnName="user_name");

2. Rename a column in the orders table
renameColumn(table="orders", columnName="createdAt", newColumnName="order_created_at");

3. Rename multiple columns in separate migration calls
renameColumn(table="products", columnName="oldPrice", newColumnName="price_old");
renameColumn(table="products", columnName="discountRate", newColumnName="discount_percent");