addForeignKeyConstraint
Adds a foreign key constraint to an existing column.
Run addForeignKeyConstraint
To run this Change Type, follow these steps:
Add the Change Type to your changeset, as shown in the examples on this page.
Specify any required attributes. Use the table on this page to see which ones your database requires.
Deploy your changeset by running the
update
command:liquibase update
Available attributes
Name | Description | Required for | Supports |
| Name of the column(s) to place the foreign key constraint on. To specify multiple columns, separate names with commas. | all | all |
| Name of the catalog of the base table | all | |
| Name of the table containing the column to constraint | all | all |
| Name of the schema of the base table | all | |
| Name of the constraint | all | all |
| Defines whether constraints are deferrable | oracle, postgresql | |
| Defines whether constraints are initially deferred | oracle, postgresql | |
|
| asany, db2, db2z, derby, firebird, h2, hsqldb, informix, ingres, mariadb, mssql, mysql, oracle, postgresql | |
|
| all except db2z | |
| Name of the column(s) the foreign key points to. To specify multiple columns, separate names with commas. | all | all |
| Name of the catalog of the referenced table | all | |
| Name of the table the foreign key points to | all | all |
| Name of the schema of the referenced table | all | |
| Set to | all | |
| [Deprecated] Boolean. | all |
Database support
Database | Notes | |
DB2/LUW | Supported | Yes |
DB2/z | Supported | Yes |
Derby | Supported | Yes |
Firebird | Supported | Yes |
Google BigQuery | Supported | Yes |
H2 | Supported | Yes |
HyperSQL | Supported | Yes |
INGRES | Supported | Yes |
Informix | Supported | Yes |
MariaDB | Supported | Yes |
MySQL | Supported | Yes |
Oracle | Supported | Yes |
PostgreSQL | Supported | Yes |
Snowflake | Supported | Yes |
SQL Server | Supported | Yes |
SQLite | Not Supported | No |
Sybase | Supported | Yes |
Sybase Anywhere | Supported | Yes |
addForeignKeyConstraint examples
--liquibase formatted sql
--changeset liquibase-docs:addForeignKeyConstraint-example
ALTER TABLE cat.address ADD CONSTRAINT fk_address_person FOREIGN KEY (person_id) REFERENCES cat.person (id) ON UPDATE RESTRICT ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;