首页 文章

Liquibase将现有的可空约束从true更改为false

提问于
浏览
0

我使用Liquibase changelog在现有表中添加了一列,并将可为空的约束设置为true .

码:

<changeSet id="10" author="000000">
    <addColumn tableName="NCV_ATTRIBUTE">
        <column name="AlternativeListPrice" type="double" defaultValue="0.0">
        <constraints nullable="true"/>
        </column>
    </addColumn>
</changeSet>

我想在changeSet 11中将可空约束从true更改为false . 实现此目的的最简单方法是什么?

谢谢 .

2 回答

  • 2

    我在这里找到了确切的方法 .

    以下是如何使用changelog删除可为空的约束:

    <changeSet id="11" author="000000">
        <dropNotNullConstraint tableName="NCV_ATTRIBUTE" columnName="AlternativeListPrice" columnDataType="double"/>
    </changeSet>
    

    关键字是“dropNotNullConstraint” .

    在此示例中,如果使用此关键字后跟表名和列名,则可以删除先前设置的可空约束,并且可以为null的值将更改为false .

  • 0

    仅在确保约束存在(在oracle中)之后运行变更集 -

    <changeSet id="111" author="ME">
      <preConditions onFail="MARK_RAN" onError="CONTINUE">
        <sqlCheck expectedResult="N">
          SELECT Nullable
          FROM user_tab_columns
          WHERE table_name = 'table_name'
          AND column_name = 'column_name'
        </sqlCheck>
      </preConditions>
      <dropNotNullConstraint tableName="BULK_REQUEST" columnName="REMARKS"/>
    </changeSet>
    

    可以找到各种数据库的先决条件here

相关问题