How to automatically set the model field during the creation ?

Note: 4 hex digits is a fairly small field - 65536 possible values. You may not have that many rows, but you will start seeing duplicate values being generated far earlier than that. (As a very rough estimator, the square root of the range gives you an idea of how soon you would get a duplicate - in this case, 256. So you can expect to start seeing duplicate values being selected about half the time once you’ve got 256 rows.)