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

2

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?

Futurity answered 1/10, 2015 at 13:39 Comment(0)
T
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.

Turnsole answered 1/10, 2015 at 14:48 Comment(5)
Can you tell me what code you looked at, please? (Package, class)Futurity
ColumnConfig: github.com/liquibase/liquibase/blob/master/liquibase-core/src/…Turnsole
And especially AddColumnChange: github.com/liquibase/liquibase/blob/master/liquibase-core/src/…Turnsole
Steve, thanks for clarifying it. There's a lack of documentation regarding default constraint values and there's an open issue for that: github.com/liquibase/liquibase.github.com/issues/74 - I hope that guys from Liquibase will fix it someday.Tend
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.Turnsole
C
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.

Carilyn answered 10/5, 2022 at 18:8 Comment(1)
For Postgres it should be NULLABLE by default, since the "NOT NULL" element will be ommited if you do not explicitly add it.Germany

© 2022 - 2024 — McMap. All rights reserved.