-
-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Which field attributes only matter for schema generation? #1850
Comments
Come to think of it, I guess that question would apply to Meta attributes as well. For example, if you don't care about schema generation, there's no point configuring: class MyModel( Model ):
class Meta:
index = ...
unique_together = ... (Except as a form of documentation.) |
Hey @ofer-pd, thanks for looking into this! aerich uses some of these attributes for generating the schema. Out of curiosity, what are you using for managing the schema? Aerich has a lot of issues, unfortunately, to the point that I think we need to suggest an alternative to the users.
We would definitely appreciate a patch! |
I currently use a home-made migration system (~250 lines) that supports migrations written in either SQL or Python, and I write migrations by hand. If I want to see the current entire schema, I use a convenience wrapper I created around I haven't had a chance to look at Aerich yet. I'm very familiar with Django's migration system, and I did briefly use SQLAlchemy's "alembic" system. I've done a little digging around for other alternatives, but it wasn't an exhaustive study. At some point I'd like to continue and complete my research before deciding how to proceed, long-term. In the meantime, I can create a PR to add the above information to the docs somewhere. |
When I discovered that
TextField
doesn't currently allowunique=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:
auto_now
,auto_now_add
,default
,generated
,max_length
,null
,pk
index
,on_delete
,unique
[1]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
orOneToOneField
withto_field
attribute pointed at a non-pk field. In that case, you do need to specifyunique=True
on the target field or Tortoise will complain.The text was updated successfully, but these errors were encountered: