XF 2.0 Why nullable entity ID?

CMTV

Well-known member
The question is stated in the title of this thread.

PHP:
@property int|null trophy_id
PHP:
'trophy_id' => ['type' => self::UINT, 'autoIncrement' => true, 'nullable' => true]

Should I do the same with my entities?

What about string IDs? String UserField ID, for example, is not marked as nullable
 

Mike

XenForo developer
Staff member
In auto_increment fields, null is used to tell MySQL to generate the next sequence value. If the column isn't tagged as nullable, then we wouldn't be able to explicitly assign null to it (while the save is pending), though this isn't necessarily something we do often. (But null is a valid value because of how MySQL interprets it.)

If it's not an auto_increment field, then primary keys shouldn't allow null.
 

Xon

Well-known member
If it's not an auto_increment field, then primary keys shouldn't allow null.
It is more accurate to say that primary keys can not contain nulls, you either need a default value or an auto_increment field and it needs to be a unique entry.
 
Top