Add new mandatory attribute to a table/entity with data


What is the best practice to add a new attribute to an existing entity/table full of data which is mandatory in one publish/deployment?

For example: There is a table customers with 1000 rows. I want to add a customertype which is mandatory and the default value is 'normal'. 

For doing this now I need two publishes/deployments. The first with the new optional attribute and fill it with the default value. The second to add the mandatory constraint. 

Is there a better solution?

Kinds regards,


Hi Willem!

You should be able to do it in one publish... Just add the attribute to the entity, set Is Mandatory to Yes, fill out the default value and publish... Just tried it on one of my modules, and had no trouble at all.

I can only see complications happening if your customertype field is a foreign key to another table (CustomerTypeId to a CustomerType static entity for example). Is this the case? 

If so, I think you would need two publishes, unless you could do something clever with a bootstrap-type timer updating all the records after publish...

Just out of curiosity, why do you not want to do two publishes?

Hi Willem,

To add to what Chris correctly wrote, mandatory fields will throw an exception only if they are FKs. For the other fields, the database will not complain if they are empty.




Thanks for the answers.

@Chris, I just don't want to do two publishes, I'd prefer to do one publish.

Ok. In the first case, adding a mandatory field, which is not a FK, can be done in one publish.

In the second case I want to add a unique key constraint (unique index) to the table. First I have to clean up the table to remove the rows which don't comply to the constraint. After that I want to add the unique key constraint (index).

Is it possible to do this in one publish/deployment?