Skip to content

Migrator

dropForeignKey()

dropForeignKey() — returns void

Available in: migration Category: Migration Functions

dropForeignKey() is used to remove a foreign key constraint from a table in the database. This is typically done during schema changes in migrations. Only available in a migration CFC.

NameTypeRequiredDefaultDescription
tablestringyesThe table name to perform the operation on
keyNamestringyesthe name of the key to drop
function up() {
    // Remove a foreign key from the orders table
    dropForeignKey(
        table="orders",
        keyName="fk_orders_customerId"
    );
}

table = "orders" -> the table that has the foreign key.

keyName = "fk_orders_customerId" -> the exact name of the foreign key constraint you want to drop.