Skip to content

Migrator

addRecord()

addRecord() — returns void

Available in: migration Category: Migration Functions

Inserts a new record into a table. This function is only available inside a migration CFC and is part of the Wheels migrator API. Useful for seeding initial data (like admin users, roles, or lookup values) alongside schema changes.

NameTypeRequiredDefaultDescription
tablestringyesThe table name to add the record to
1. Add a single record
addRecord(
    table="people",
    id=1,
    title="Mr",
    firstname="Bruce",
    lastname="Wayne", 
    email="bruce@wayneenterprises.com",
    tel="555-67869099"
);

Inserts one record into the people table.

2. Add a record with only required fields
addRecord(
    table="roles",
    id=1,
    name="Admin"
);

Seeds an Admin role into the roles table.

3. Add a record with default values in schema
addRecord(
    table="users",
    email="new@example.com",
    firstName="new",
    lastName="user"
);

Relies on schema defaults (e.g., isActive=true) for missing fields.

4. Add lookup data
addRecord(
    table="statuses",
    id=1,
    name="Pending"
);
addRecord(
    table="statuses",
    id=2,
    name="Approved"
);
addRecord(
    table="statuses",
    id=3,
    name="Rejected"
);

Seeds reusable lookup/status values.

5. Add a record referencing another table
// Assuming user with ID=1 exists
addRecord(
    table="posts",
    id=1,
    title="First Post",
    content="Hello, Wheels!",
    userId=1
);

Creates a post tied to an existing user.