【问题标题】:What is the default nullable constraint setting for a liquibase column?liquibase 列的默认可为空约束设置是什么?
【发布时间】:2022-05-11 02:08:38
【问题描述】:

我正在创建一个新表,如下所示:

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

nullable 约束而言,如果我省略该属性,默认设置是什么?

例如, 如果我只这样做:

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

...该列是否可以为空?

更重要的是,指定这一点的文档在哪里(因为我还有其他类似的问题)?

我看了这里:Liquibase Column Tag,但它只说模棱两可:

可为空 - 列是否可以为空?

【问题讨论】:

    标签: nullable liquibase


    【解决方案1】:

    它没有记录,但我查看了源代码,似乎如果您不指定,则没有向列添加约束。您可以自己检查的一种方法是使用 liquibase updateSql 命令查看生成的 SQL。

    【讨论】:

    【解决方案2】:

    其实是记录在案的here

    定义列是否可以为空。 默认:依赖数据库

    所以默认的空约束是依赖于数据库的。 例如,如果您使用 Postgres,则默认情况下它不能为空。

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

    对列使用 NOT NULL 约束以强制列不接受 NULL。 默认情况下,一列可以保存 NULL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 2021-04-26
      相关资源
      最近更新 更多