DEV Community

Discussion on: Data constraints: database layer or app logic?

Collapse
 
rhymes profile image
rhymes

Both. I use both when I use RDBMS.

You never know how your data is going to get into the DB, it might not always use the ORM layer. Also sometimes you might forget to enforce a certain rule and, typical situation, end up with null values in columns that are not supposed to have null values :D

I agree DB constraints can be a pain in the ass but if it happens a lot maybe there's an error in the app design?

Collapse
 
suprnova32 profile image
Patricio Cano

👍 here. You can always find a way to skip the app layer, specially on the console for RoR, for example. Data constraints should be added to the DB first, and then as a sanity check, added to the app layer.