Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 799
LimaNightHawk Avatar asked Oct 01 '15 13:10

LimaNightHawk


2 Answers

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.

like image 58
SteveDonie Avatar answered Oct 26 '22 21:10

SteveDonie


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 NOT 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.

like image 1
provisota Avatar answered Oct 26 '22 22:10

provisota