What would be the best approach to having a system in place and running for over a year and then adding a new field to the table. I would like this new field to be ‘required’ for any new entry, but not existing ones.
You can make custom validation. How your pk is incremented? Does it have auto increment in db or you manually set the id. For ProjectID > 51000. Some records may be removed before but your pk is on 51001 or something else. Does it matter in validation?
I would take the following approach:
Make the new field a NULL column in the db.
Use a validation rule with “when” function (and whenClient if necessary). Check $model->isNewRecord, + $model->id > x, or $model->created > date, or whatever your exact properties are that can be used to exclude old records.
This way users can update old records without having to add the new property, and new ones will require it.
search for “yii2 custom validator” and you will find what you need.