Skip to content

Which field attributes only matter for schema generation? #1850

Open
@ofer-pd

Description

@ofer-pd

When I discovered that TextField doesn't currently allow unique=True, it got me thinking... does it matter?

I don't use Tortoise to generate my schema, so there's no point setting field attributes that only matter for schema generation — other than as a form of documentation, which can be accomplished just as well in a comment.

So I did some skimming of the code and confirmed that index does, indeed, only matter for the sake of schema generation.


So, the next question is — which field attributes affect Tortoise behavior, and which only matter for schema generation? And might it be useful to describe that in the docs?

After some more skimming, I reached the following conclusions:

  • Attributes that affect Tortoise behavior: auto_now, auto_now_add, default, generated, max_length, null, pk
  • Attributes that only matter for schema generation: index, on_delete, unique[1]
  • Attributes that only matter for schema generation, but are required by the field constructor so you have to specify them anyway: max_digits, decimal_digits

Note: I skipped a few that don't currently matter to me.


Would the authors like to comment on this topic, and also, would they appreciate a patch to add something like this to the docs?


[1] The exception is if configuring a ForeignKeyField or OneToOneField with to_field attribute pointed at a non-pk field. In that case, you do need to specify unique=True on the target field or Tortoise will complain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions