How to customize unique colum in postgresql

I need create a column name my_referal_code = <6 digit>
It should be automatically created like id column or like this

But its have some condition it should contain with num and caps letters
compinations = 36 * 35 * 34 * 33 * 32 * 31 = 1447649280

How can i configure that

I have found some alternative solutions here

it may help you, but it’s not satisfied

Can you provide a little more detail and perhaps be more clear about exactly what it is you’re trying to achieve?

I want to create a field in User model, the field should cotain 6 digits letter, it contains num or capital letters and also the field should be unique how can i achieve that

Should the field always have exactly 6 characters?

To clarify, the set of valid characters are 0-9, a-z, A-Z?

In general, to do this, you’ve got a couple different options.

The most performant and robust solution would be to create a custom field in the database, using a trigger to set the value when the object is being written to the database.

You can do this in Django, but you need to ensure that you have a table lock on the User model while you’re creating the value and checking it for uniqueness.

Another solution is to determine whether you really need to store that value in the database. Depending upon your application’s true requirements, you could create a transformation function that converts the autoincrement field into that representational format when it needs to be exposed to the outside world. (Again, that’s a decision that needs to be driven by the underlying requirements.)

To clarify, the set of valid characters are 0-9, a-z, A-Z?
YES

This is for referal_code for every user it should be unique, thats why im telling this

Use a Regex Validator for the pattern [Validators | Django documentation | Django] and add validator to your field.

To make a column as Primary Key use primary_key=True in my_referal_code definition.

But I suggest, you to let Django define the primary keys on models unless you have specific reason to do so.