addColumn
The addColumn
Change Type adds a new column to an existing table.
Uses
You can typically use the addColumn
Change Type when you want to add a new column and deploy it to the table in your database.
Running the addColumn
Change Type
To create a column for your table, follow these steps:
Step 1: Add the addColumn
Change Type to your changeset with the needed attributes as it is shown in the examples.
Step 2: Deploy your changeset by running the update
command.
liquibase update
Now, you should see a new column.
Available attributes
Name | Description | Required for | Supports |
---|---|---|---|
catalogName | The name of the catalog | all | |
schemaName | The name of the schema | all | |
tableName | The name of the table to add the column | all | all |
Nested properties
Name | Description | Required for | Supports | Multiple allowed |
---|---|---|---|---|
columns | The column constraint and foreign key information. Setting the defaultValue attribute will specify a default value for the column. Setting the value attribute will set all rows existing to the specified value without modifying the column default.See Information about the <column> tag section for more information. |
all | all | yes |

<changeSet author="liquibase-docs" id="addColumn-example">
<addColumn catalogName="cat"
schemaName= "public"
tableName="person" >
<column name="address"
position="2"
type="varchar(255)"/>
<column afterColumn="id"
name="name"
type="varchar(50)" >
<constraints nullable="false" />
</column>
</addColumn>
</changeSet>

databaseChangeLog:
- changeSet:
id: addColumn-example
author: liquibase-docs
changes:
- addColumn:
tableName: person
columns:
name: middlename
type: varchar(50)

{
"changeSet":{
"id":"addColumn-example",
"author":"liquibase-docs",
"changes":[
{
"addColumn":{
"catalogName":"cat",
"columns":[
{
"column":{
"name":"address",
"position":2,
"type":"varchar(255)"
}
},
{
"column":{
"afterColumn":"id",
"constraints":{
"nullable":false
},
"name":"name",
"type":"varchar(50)"
}
}
],
"schemaName":"public",
"tableName":"person"
}
}
]
}
}

ALTER TABLE cat.person ADD address VARCHAR(255) NULL,
ADD name VARCHAR(50) NOT NULL AFTER `id`;
Database support
Database | Notes | Auto rollback |
---|---|---|
DB2/LUW | Supported | Yes |
DB2/z | Supported | Yes |
Derby | Supported | Yes |
Firebird | 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 | Supported | Yes |
Sybase | Supported | Yes |
Sybase Anywhere | Supported | Yes |

<column>
tag
The <column>
tag is a tag that is re-used throughout the Liquibase XML when column definitions and column information is needed. As a result, not all the attributes of column are valid in each context it is used in.
Available attributes
Attribute | Description |
---|---|
name | The name of the column. |
type | The column data type. |
value |
The value for which to set the column. The value will be surrounded by quote marks and nested quote marks will be escaped. Note: Setting the |
computed | The attribute which is used if the value in name isn't actually a column name but a function. Since 3.3.0 |
valueNumeric | The numeric value to set the column to. The value will not be escaped and will not be nested in quote marks. |
valueBoolean | The boolean value to set the column to. The actual value string inserted will depend on the database implementation. |
valueDate | The date and time value to set the column to. The value is specified in one of the following forms: YYYY-MM-DD , hh:mm:ss , or YYYY-MM-DDThh:mm:ss . |
valueComputed | The value that is returned from a function or procedure call. This attribute will contain the function to call. |
valueBlobFile |
The path to a file, whose contents will be written as a BLOB (i.e. chunk of binary data). The path to the changelog file location must be either absolute or relative. An example of an absolute path is: /usr/local/somefile.dat on Unix or c:\Directory\somefile.dat on Windows. Note: Refer to java.io.File javadoc for the details of what to consider relative or absolute path). |
valueClobFile | The path to a file, whose contents will be written as a CLOB (i.e. chunk of character data). The path to the changelog file location must be either absolute or relative. An example of an absolute path is: /usr/local/somefile.dat on Unix or c:\Directory\somefile.dat on Windows. Note: Refer to java.io.File javadoc for the details of what to consider relative or absolute path). |
encoding | The name of the encoding (specified in java.nio.Charset javadoc, e.g. "UTF-8") of the CLOB file (specified in valueClobFile) contents. Note: The attribute is used only when valueClobFile attribute is specified. Otherwise, it is ignored. |
defaultValue | The default value for column.
Note: If you don't set the first value, the |
defaultValueNumeric | The default numeric value for column. |
defaultValueBoolean | The default boolean value for column. |
defaultValueDate | The default date and time value for column. The value is specified in one of the following forms: YYYY-MM-DD , hh:mm:ss , or YYYY-MM-DDThh:mm:ss . |
defaultValueComputed | The default value that is returned from a function or procedure call. This attribute will contain the function to call. |
autoIncrement | The auto-increment column. Ignored on databases that do not support the autoincrement/identity functionality. |
startWith | The value auto-increment start. Ignored on databases that do not support autoincrement/identity functionality. |
incrementBy | The value of each step by auto-increment. Ignored on databases that do not support autoincrement/identity functionality. |
remarks | A short description of the column (column comment). |
beforeColumn | The attribute that allows you to control where in the table column order the new column goes if it is used in an addColumn command. Only one of beforeColumn , afterColumn , or position is allowed. Since 3.1 |
afterColumn | The attribute that allows you to control where in the table column order the new column goes if it is used in an addColumn command. Only one of beforeColumn , afterColumn , or position is allowed. Since 3.1 |
position | The attribute that allows you to control where in the table column order the new column goes if it is used in an addColumn command. Only one of beforeColumn , afterColumn , or position is allowed. Uses one based index. Since 3.1 |
descending | The boolean attribute which allows you to specify that a column should be used in a descending order in the index if it is used in a createIndex command. Default value is false (in an ascending order) Since 3.4 |
To help make scripts database-independent, the following generic
data types will be converted to the correct database implementation:
- BOOLEAN
- CURRENCY
- UUID
- CLOB
- BLOB
- DATE
- DATETIME
- TIME
- BIGINT
Also, specifying a java.sql.Types.*
type will be converted to the correct type as well. See the following examples:
- java.sql.Types.TIMESTAMP
- java.sql.Types.VARCHAR(255)
Available sub-tags
Tag | Description |
---|---|
constraints | Constraint definitions |
Constraints tag
The <constraints>
tag contains information about constraints on the column.
Available attributes
Attribute | Description |
---|---|
nullable | The attribute that defines whether the column is nullable. |
notNullConstraintName | The not null constraint name. |
primaryKey | The attribute that defines whether the column is a primary key. |
primaryKeyName | The primary key name Since 1.6. |
primaryKeyTablespace | The tablespace to use for the defined primary key. |
unique | The attribute that defines whether a unique clause should be applied. |
uniqueConstraintName | The unique constraint name. |
references | The foreign key definition. |
referencedTableCatalogName | The name of the catalog. |
referencedTableSchemaName | The name of the schema. |
referencedTableName | The name of the table. |
referencedColumnNames | The name of the column. |
foreignKeyName | The foreign key name. |
deleteCascade | The attribute that sets delete cascade . |
deferrable | The attribute that defines whether constraints are deferrable. |
initiallyDeferred | The attribute that defines whether constraints are initially deferred. |
validateNullable | The attribute that defines whether to validate the defined not null constraint. |
validateUnique | The attribute that defines whether to validate the defined unique constraint. |
validatePrimaryKey | The attribute that defines whether to validate the defined primary key constraint. |
validateForeignKey | The attribute that defines whether to validate the defined foreign key constraint. |
checkConstraint | The attribute that defines whether to validate the defined check constraint. |