1

Can I do the following to make a charfield unique and not null using tortoise orm?

class User(Model):
    id = fields.IntField(pk = True)
    username = fields.CharField(max_length = 128, unique = True, nullable = False)

Or what would be the appropriate field? Is there a field for email type data? or which one should be used Thank you!

Diego L
  • 185
  • 1
  • 9

1 Answers1

0

The docs specify max_input and **kwargs as input parameters for CharField.

https://tortoise-orm.readthedocs.io/en/latest/fields.html#tortoise.fields.data.CharField

You can find the **kwargs for CharField in its parent class, the base Field.

https://tortoise-orm.readthedocs.io/en/latest/fields.html#tortoise.fields.base.Field

There you find parameters like:

  • null (bool) – Is this field nullable?
  • unique (bool) – Is this field unique?
  • validators (Optional[List[Union[Validator, Callable]]]) – Validators for this field.

See the docs for more info on how to use validators: https://tortoise-orm.readthedocs.io/en/latest/validators.html

Loknar
  • 1,169
  • 2
  • 13
  • 38