11
Views
5
Comments
Solved
Issue related to Not Null constraint when Is mandatory is already set in Columns

In outsystem database if we create a column with is mandatory as yes but still it does not create the column as not null in underlying database. Can you please tell me reason behind it?

2024-09-12 07-55-10
Sana Shaikh
Solution

Hello @Arnab Karmaker 

In OutSystems, when you mark a column as Mandatory in the data model, it does not necessarily translate to a NOT NULL constraint in the underlying database. This behavior is due to how OutSystems manages data consistency and application logic. OutSystems enforces the Mandatory constraint at the application layer instead of the database layer. This allows the platform to ensure data integrity while keeping the underlying database schema flexible for future changes. When you mark a column as Mandatory, OutSystems automatically validates the data before committing it to the database. If an attempt is made to leave the column empty, the platform raises a validation error at runtime, preventing invalid data from being saved. If the database schema used a NOT NULL constraint, altering it later (e.g., making the column optional) would require database migration scripts to remove the constraint. By avoiding a NOT NULL constraint, OutSystems ensures smoother schema updates without requiring low-level database changes. 

OutSystems often manages default values for columns behind the scenes. E.g: a Mandatory column of type Text might be stored as an empty string ('') or a Mandatory column of type Integer might have a default value of 0.

Because of this default value assignment, a NOT NULL constraint is less relevant in practice, as the platform always ensures a value is present before committing data.

Hope this helps.

UserImage.jpg
Arnab Karmaker

Thank you, Sana, it was helpful.

2024-09-12 07-55-10
Sana Shaikh


I'm glad you found the solution! Please mark it as the accepted answer so others with the same question can benefit from it. Always happy to help! 😊 

UserImage.jpg
Arnab Karmaker

Replying to Sana Shaikh's comment on 16 Dec 2024 11:32:4, if we change the column as NOT NULL from NULL in the external database, will that cause any errors in the application side?
2024-09-12 07-55-10
Sana Shaikh

Logically it should not cause any error but if the column already contains NULL values, changing it to NOT NULL will cause a constraint violation. You will need to update the existing data to ensure there are no NULL values before applying the change. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.