Skip to content

Migrator

execute()

execute() — returns void

Available in: migration Category: Migration Functions

execute() allows you to run a raw SQL query directly from a migration file. This is useful when you need to perform operations that aren’t easily handled by the built-in migration methods like createTable() or addColumn(). Only available in a migration CFC

NameTypeRequiredDefaultDescription
sqlstringyesArbitary SQL String
<cfscript>
function up() {
  transaction {
     // Execute a raw SQL statement
     execute(sql="INSERT INTO users (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')");
  }
}
</cfscript>