LimaNightHawk
LimaNightHawk

Reputation: 7083

What is the default nullable constraint setting for a liquibase column?

I'm creating a new table, like this:

    <createTable tableName="myTable">
        <column name="key" type="int" autoIncrement="true">
            <constraints primaryKey="true" primaryKeyName="PK_myTable" nullable="false"/>
        </column>
        <column name="name" type="nvarchar(40)">
            <constraints nullable="false"/>
        </column>
        <column name="description" type="nvarchar(100)">
            <constraints nullable="true"/>
        </column>
    </createTable>

As far as the nullable constraint, if I omit that attribute what is the default setting?

E.g., If I only did this:

<column name="description" type="nvarchar(100)"/>

...would the column be nullable?

More importantly, where is the documentation that specifies this (as I have other questions like this)?

I looked here: Liquibase Column Tag, but it only says ambiguously:

nullable - Is column nullable?

Upvotes: 17

Views: 22558

Answers (2)

provisota
provisota

Reputation: 1660

Actually it's documented here.

Defines whether the column is nullable. Default: database-dependent

So the default null constraint is database-dependent. If you use Postgres, for example, it will be nullable by default.

https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-not-null-constraint/

Use the NOT NULL constraint for a column to enforce a column not accept NULL. By default, a column can hold NULL.

Upvotes: 2

SteveDonie
SteveDonie

Reputation: 9016

It isn't documented, but I looked at the source code and it appears that if you do not specify, there is no constraint added to the column. One way you can check this yourself is to use the liquibase updateSql command to look at the SQL generated.

Upvotes: 15

Related Questions