Opened 3 years ago
Last modified 22 months ago
#31583 new New feature
Extend deferred unique constraint support to OneToOneField
Reported by: | BorisZZZ | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | DEFERRED |
Cc: | Ian Foote, Petr Přikryl | Triage Stage: | Someday/Maybe |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Support for DEFERRABLE INITIALLY DEFERRED was added in https://code.djangoproject.com/ticket/20581 . It would be great if it could be extended to the implicit Unique constraint generated by OneToOneField
, say, by adding an argument:
OneToOneField(OtherModel, defer=models.Deferrable.DEFERRED)
Change History (4)
comment:1 Changed 3 years ago by
Triage Stage: | Unreviewed → Someday/Maybe |
---|
comment:2 Changed 2 years ago by
Cc: | Ian Foote added |
---|
comment:3 Changed 22 months ago by
Cc: | Petr Přikryl added |
---|
comment:4 Changed 22 months ago by
I think it would be quite easy. Here we could pass deferrable
argument based on new_field.defer
value:
https://github.com/django/django/blob/4.0/django/db/backends/base/schema.py#L810
https://github.com/django/django/blob/4.0/django/db/backends/base/schema.py#L1245
Not sure we should do that as it seems pretty niche.
I guess an alternative API could be to allow passing a
UniqueConstraint
to theunique
kwarg like we've discussed doing to theField.index
one.e.g.