Migrator
timestamp()
Signature
Section titled “Signature”timestamp() — returns any
Available in: tabledefinition
Category: Table Definition Functions
Description
Section titled “Description”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.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
columnNames | string | no | — | |
default | string | no | — | |
allowNull | boolean | no | — | |
columnType | string | no | datetime |
Examples
Section titled “Examples”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")