I have encountered this problem a number of times. Let's say you have a large object that you want to store in the database. Perhaps it's a dating profile for a user, and it has 100 fields. All of these 100 fields should have a value, once the profile is complete.
However, you want to avoid forcing the user to enter all 100 fields in one go! Perhaps they can create their profile section by section, but it is not considered "complete" until all 100 fields have a value.
It would be nice not to allow these fields to be
NULL. After all,
NULL is not a valid value for them. But if the fields are
NOT NULL, you can't build the row up bit by bit, saving a few fields each time.
"Solutions" I have used in the past:
- Just make the fields nullable. This is not great, as you are losing some guarantees of data integrity. A bug in your app leads to inconsistent data.
- Split the 100 fields into several tables. Make all the fields
NOT NULL. This adds complexity to queries, and seems a bit wrong - a completed profile should not have a row in one table but not another, but the DB schema allows this.
What are some good ways of handling this?