16

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?

SteveDonie
  • 8,700
  • 3
  • 43
  • 43
LimaNightHawk
  • 6,613
  • 3
  • 41
  • 60

2 Answers2

15

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.

SteveDonie
  • 8,700
  • 3
  • 43
  • 43
  • Can you tell me what code you looked at, please? (Package, class) – LimaNightHawk Oct 01 '15 at 14:54
  • 1
    ColumnConfig: https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/change/ColumnConfig.java – SteveDonie Oct 02 '15 at 19:10
  • And especially AddColumnChange: https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/change/core/AddColumnChange.java#L100-L102 – SteveDonie Oct 02 '15 at 19:13
  • Steve, thanks for clarifying it. There's a lack of documentation regarding default constraint values and there's an open issue for that: https://github.com/liquibase/liquibase.github.com/issues/74 - I hope that guys from Liquibase will fix it someday. – ilyailya Nov 18 '16 at 16:28
  • 6
    Note that there are no "guys" from Liquibase - just one guy. Everyone else is just like you - a potential contributor. I know the Liquibase team (that one guy) welcomes pull requests, and the documentation is also in github. – SteveDonie Nov 18 '16 at 21:09
2

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.

João Portela
  • 6,338
  • 7
  • 38
  • 51
provisota
  • 1,390
  • 1
  • 14
  • 14
  • 1
    For Postgres it should be NULLABLE by default, since the "NOT NULL" element will be ommited if you do not explicitly add it. – Leander Sep 16 '22 at 11:31