2017-02-13 25 views
0

我使用Liquibase更改日誌將列添加到現有表中,並將可空約束設置爲true。Liquibase將現有空可約束從true更改爲false

代碼:

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

我想可空約束從真更改爲假的變更11.什麼是實現這一目標的最簡單的方法?

謝謝。

+0

請不要標記這是一個Java問題,當它有與Java完全沒有關係。 –

回答

1

我發現了在這裏使用的確切方法。

下面是如何使用的changelog去除可空約束:

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

的關鍵詞是 「dropNotNullConstraint」。

在本例中,如果您使用此關鍵字,然後是表名和列名,您將能夠刪除先前設置的可空限制條件,並且可爲空的值將更改爲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

相關問題