Your Question

Supposed I have a model:

type Issue struct {
    gorm.Model
    UserLevel string `gorm:"type:TINYINT;not null;DEFAULT:0;check:user_level <= 2" json:"userLevel"`
    PriorityLevel uint    `gorm:"type:TINYINT;not null;DEFAULT:0;check:priority_level <= 5" json:"priorityLevel"`
}

When a check constraint failed, I only see the this message every time:

....Check constraint 'chk__<column_name>' is violated.

How can I add a custom check constraint error message when a check is failed?

So I want...
If check on `UserLevel` failed: I want to see: Check constraint 'chk__<userLevel>' failed: user level should be from 0 to 2
Or
If check on `PriorityLevel` failed: I want to see: Check constraint 'chk__<priorityLevel>' failed: priority level should be from 0 to 5

In the normal SQL (MySQL) specifically, I think we can do this:

ADD CONSTRAINT 
[Foo cannot be greater than Bar. Please be sure to check your foos and bars next time.] 
CHECK (foo <= Bar)

Thanks in advance!