Default Value for Column

Hello,

I wonder if is possible to set a default column value as an attribute or something else.
I need it to add a new field with mandatory attribute and a default.

I don’t know if this has changed much from CUBA, here is how it was done in CUBA and may just work with Jmix: Initial Entity Values

Hi Marc, thanks for your answer.

I don’t think the approach you described will help in my case.
I already have the table on the DB and it’s populated.
If I add a new mandatory field to the structure without a default value the DB deploy will fail because the old records does not have any value for this new field.

Googoling for “liquibase default value column” I found that is possible to change the “Changelog” file but is something not really comfortable.

The default value is quite standard in all database and I think it would be nice to have it in the designer.

Hi,

setting a default value after making a DB value mandatory is supported by Jmix studio.

When you mark an attribute as mandatory, the next start of the application will show the DB update changelogs. When you click on the corresponding changelog: <addNotNullConstraint />, there is a checkbox for “Update NULL values”.
CleanShot 2021-08-17 at 21.29.35@2x

Clicking allows you to define the default value that liquibase should set on DB update.

CleanShot 2021-08-17 at 21.30.05@2x

I hope this helps.

Cheers
Mario

2 Likes

Grazie Mario, perfetto