The simplest method is to just ignore your perceived problem. Items that are in the database have an id, provided by the database. Items not in the database have no id. Both are valid states. “Insert” is not a valid operation if the item has an I’did that is not null. And “update” is an invalid operation if the item is not in the database.
You can decide whether id should be immutable - in that case adding an item to the database leads to the creation of a new item with the id changed.