Sometimes the auto rollback does not work with constraint change type

I am testing the auto rollback function for change type dropNotNullConstraint, however the auto rollback failed with error Cannot insert the value NULL into column 'name', table 'liquibase.dbo.person'; column does not allow nulls. UPDATE fails.

Here’s what I did:

  1. Create a NOT NULL constraint with createTable PERSON in column NAME
  2. Drop the not null constraint with dropNotNullConstraint in column NAME
  3. My application starts running, which will create a data with null NAME (this database change is not recorded in Liquibase)
  4. Rollback the dropNotNullConstraint from step 2

According to Liquibase dropNotNullConstraint Documentation, it should support auto rollback. But in my case, it fails.

I can easily prevent the error by writing my own rollback script, i.e. delete the null NAME data before dropping the null constraint. However I wonder, when should I create my own rollback script? Although the change type supports auto rollback, will the auto rollback fails when some data violates the rollback action?

Much appreciated for any help.

Please help :pray::pray::pray::pray::pray::pray::pray::pray::pray::pray::pray::pray::pray::pray::pray:

The dropNotNullConstraint auto-rollback is working as expected, it’s dropping the Not Null constraint. It has no way of correcting the data in the table that your application modified outside of Liquibase.

You should just write a custom rollback script for this scenario.

I see, thanks @daryldoak. So I should pay attention to the drop constraint change type even though it supports auto rollback.

I don’t think the other drop constraint change-types would have the same data issue.

I see, thanks for your help @daryldoak!