Skip to content

Migrator

dropTable()

dropTable() — returns void

Available in: migration Category: Migration Functions

dropTable() is used to remove a table from the database entirely. This is a destructive operation, so all data in the table will be lost. Only available in a migration CFC

NameTypeRequiredDefaultDescription
namestringyesName of the table to drop
function down() {
    // Drop the 'users' table
    dropTable(name="users");
}

name = "users" -> the table that you want to remove from the database.

Notes

Typically used in the down() method of a migration when rolling back a previous createTable().

Can be combined with transaction {} to ensure rollback in case of errors:

function down() {
    transaction {
        try {
            dropTable("orders");
        } catch (any e) {
            transaction action="rollback";
            throw(errorCode="1", detail=e.detail, message=e.message, type="any");
        }
        transaction action="commit";
    }
}

Caution: This operation permanently deletes all data in the table.