Skip to content

Instance Method

foreignKey(_:references:_:onDelete:onUpdate:named:)

Add a FOREIGN KEY constraint to the table.
@discardableResult func foreignKey(_ columns: [String], references foreignTable: String, _ foreignColumns: [String], onDelete: SQLForeignKeyAction? = nil, onUpdate: SQLForeignKeyAction? = nil, named constraintName: String? = nil) -> Self

Parameters

columns

One or more columns to include in the constraint.

foreignTable

The table referenced by the constraint.

foreignColumns

The foreign table columns corresponding to the constrained columns.

onDelete

Optional foreign key action to perform on delete.

onUpdate

Optional foreign key action to perform on update.

constraintName

An optional name to give the constraint.