Skip to content

Migrator

timestamp()

timestamp() — returns any

Available in: tabledefinition Category: Table Definition Functions

Used to add one or more TIMESTAMP (or DATETIME) columns to a table definition. It lets you specify default values, whether the column allows NULL, and even override the underlying SQL type through the columnType argument. This is especially useful when you need to track creation and update times or work with custom timestamp fields. Only available in a migrator CFC.

NameTypeRequiredDefaultDescription
columnNamesstringno
defaultstringno
allowNullbooleanno
columnTypestringnodatetime
1. Add a basic timestamp column
t.timestamp("createdAt")

2. Add multiple timestamp columns
t.timestamp("createdAt, updatedAt")

3. Add a timestamp column with a default value
t.timestamp(columnNames="createdAt", default="CURRENT_TIMESTAMP")

4. Add a nullable timestamp column
t.timestamp(columnNames="deletedAt", allowNull=true)

5. Override column type to use TIMESTAMP instead of DATETIME
t.timestamp(columnNames="syncedAt", columnType="timestamp")