addNotNullConstraint

Adds a not-null constraint to an existing table. If a defaultNullValue attribute is passed, all null values for the column will be updated to the passed value before the constraint is applied.

Available attributes

Name Description Required for Supports
catalogName Name of the catalog all
columnDataType Current data type of the column informix, mariadb, mssql, mysql all
columnName Name of the column to add the constraint to all all
constraintName Created constraint name (if database supports names for NOT NULL constraints) all
defaultNullValue Value to set all currently null values to. If not set, change will fail if null values exist all
schemaName Name of the schema all
tableName Adds a not-null constraint to an existing table. If a defaultNullValue attribute is passed, all null values for the column will be updated to the passed value before the constraint is applied. all all
validate This is true if the not null constraint has 'ENABLE VALIDATE' set, or false if the not null constrain has 'ENABLE NOVALIDATE' set. all

XML example

<changeSet  author="liquibase-docs"  id="addNotNullConstraint-example">  
    <addNotNullConstraint  catalogName="cat"  
            columnDataType="int"  
            columnName="id"  
            constraintName="const_name"  
            defaultNullValue="A String"  
            schemaName="public"  
            tableName="person"  
            validate="true"/>  
</changeSet>

YAML example

changeSet:  
  id:  addNotNullConstraint-example  
  author:  liquibase-docs  
  changes:  
  -  addNotNullConstraint:  
      catalogName:  cat  
      columnDataType:  int  
      columnName:  id  
      constraintName:  const_name  
      defaultNullValue:  A String  
      schemaName:  public  
      tableName:  person  
      validate:  true

JSON example

{  "changeSet":  {  "id":  "addNotNullConstraint-example",  "author":  "liquibase-docs",  "changes":  [  {  "addNotNullConstraint":  {  "catalogName":  "cat",  "columnDataType":  "int",  "columnName":  "id",  "constraintName":  "const_name",  "defaultNullValue":  "A String",  "schemaName":  "public",  "tableName":  "person",  "validate":  true  }  }]  }  }

SQL example

UPDATE  cat.person  SET  id  =  'A String'  WHERE  id  IS  NULL;  

ALTER  TABLE  cat.person  MODIFY  id  INT  NOT  NULL;

Database support

Database Notes Auto rollback
DB2/LUW Supported Yes
DB2/z Not Supported Yes
Derby Supported Yes
Firebird Not 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
SQL Server Supported Yes
SQLite Not Supported Yes
Sybase Supported Yes
Sybase Anywhere Supported Yes