The ConstraintMustExist check allows you to specify an individual table or column by name to check that it has one or more specific Constraints.

  • Checks require specific parameters noted in the table.
  • Customizations to checks configuration are stored in the liquibase.checks-settings file.


You can use the check to ensure a specific table contains specific elements, such as a primary key, default values, or other constraints. This upholds the critical data architecture decisions and ensures that non-compliance problems are identified as early as possible.

Run the ConstraintMustExist check

In this example, we will say that we have a table.column name already and one or more required constraints exist. First, ensure you have a Liquibase Lab license, a valid URL property, and the checks-scope property includes database. The checks-scope is set in the default properties file, environment variable, or any standard method. Then, check the table for constraints. Enable the ConstraintMustExist check by running the following command in the CLI: 

liquibase checks enable --check-name=ConstraintMustExist
Liquibase then prompts you to establish a copy of this check and to initiate the customization work flow. To do this, the user must select options for each of the attributes below in the CLI.

Note: This check can not be enabled directly because one or more fields does not have a default value. Creating a copy of this check initiates the customization work flow.

Available Attributes

Attribute Name Type Description Options/ Validation Default Value
ConstraintOperator String/enum

The location to look for the provided SearchString value

- startsWith - SearchString provided should be found at the beginning of the table.

- endsWith - SearchString provided should be found at the end of the table.

- contains - SearchString Provided can be anywhere in the table.

- regexp - SearchString provided is a regexp that should be matched.

all-- Check all tables for specified constraint.

TableName String/enum Optional: The table name string or regex to match. (Note: leave blank to check all tables for column name.)    
ColumnName String/enum The column name string or regex to match.    
CaseSensitivity String/enum Set CASE_SENSITIVE (options: true, false) user entry of true or false is accepted case-insensitively false
Constraint String/enum Enter the required constraint(s), separate NOT NULL, UNIQUE, PRIMARYKEY, FOREIGNKEY PRIMARYKEY
Message String/enum The message you wish to print when the check detects a pattern match

A match for regular expression {{SearchString}} value was detected in Changeset changeset id.
Severity String/enum Set CASE_SENSITIVE (options: true, false) user entry of true or false is accepted case-insensitively false

After you select your options, liquibase checks enable --check-name=ConstraintMustExist will run successfully.