Creating Table Constraints
Sometimes you want to add constraints on a table level, rather than a column level. The following methods will let you accomplish that.
index
Create a generic index from one or more columns.
Argument | Type | Required | Default | Description |
columns | string or array |
| The column or array of columns that make up the index. | |
name | string |
| A generated name consisting of the table name and column name(s). | The name of the index constraint. |
Example:
SchemaBuilder
SQL (MySQL)
foreignKey
Create a foreign key constraint from one or more columns. Follow up this call with calls to the TableIndex
's references
and onTable
methods.
Argument | Type | Required | Default | Description |
columns | string or array |
| The column or array of columns that references a key or keys on another table. | |
name | string |
| A generated name consisting of the table name and column name(s). | The name of the foreign key constraint. |
Example:
SchemaBuilder
SQL (MySQL)
primaryKey
Create a primary key constraint from one or more columns.
Argument | Type | Required | Default | Description |
columns | string or array |
| The column or array of columns that make up the primary key. | |
name | string |
| A generated name consisting of the table name and column name(s). | The name of the primary key constraint. |
Example:
SchemaBuilder
SQL (MySQL)
unique
Create a unique constraint from one or more columns.
Argument | Type | Required | Default | Description |
columns | string or array |
| The column or array of columns that make up the unique constraint. | |
name | string |
| A generated name consisting of the table name and column name(s). | The name of the unique constraint. |
Example:
SchemaBuilder
SQL (MySQL)