Skip to contents

Define a foreign key column

Usage

ForeignKey(type, references, on_delete = NULL, on_update = NULL, ...)

Arguments

type

SQL data type (e.g. "INTEGER")

references

Character. The referenced table and column (e.g. "users.id")

on_delete

Optional ON DELETE behavior (e.g. "CASCADE")

on_update

Optional ON UPDATE behavior

...

Reserved for extras like CHECK, COLLATE, etc.

Value

A ForeignKey object

Details

This function creates a ForeignKey object, which is a special type of Column. It inherits all properties of a Column and adds foreign key specific attributes. See Column for details on additional parameters that can be passed via ....

See also

Examples

# Define a foreign key referencing the 'id' column in the 'users' table
user_id_fk <- ForeignKey("INTEGER", references = "users.id", on_delete = "CASCADE")

# Define a nullable foreign key with custom update behavior
category_id_fk <- ForeignKey("INTEGER", references = "categories.id",
                             nullable = TRUE, on_update = "SET NULL")