Hi,
The Given code is wrong, you are mapping the user id to the hr.department model. What happens is that, you have to store the id of the department to the field dep, instead of giving the id of department, you are passing the id of the user as default value.
For example,
In departments table/model, you have 3 records, ABC with iD 1, XYZ with ID 2 and LMN with ID 3. Now user with the ID 2 logged into system, the assigned department will be XYZ as its ID is 2 and now if user with ID 1 is logged in the assigned department will be ABC as its ID is 1.
The Error will be raised when a user with ID 4 or other logged in, now as the default value it returns user id , here user id is 4 and there is no record with ID 4 in department table/model, so adjust your logic to get the default department ID and do accordingly.
Thanks