Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30670 closed Cleanup/optimization (fixed)

Document SchemaEditor.add_constraint()/remove_constraint() methods.

Reported by: Akash Agrawal Owned by: Akash Agrawal
Component: Documentation Version: 2.2
Severity: Normal Keywords: SchemaEditor, unique_together, constraints
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Since Django 2.2, UniqueConstraint is introduced for unique_together. But there is no supporting function to alter it using SchemaEditor. It still has alter_unique_together using the old unique_together.

Change History (13)

comment:1 by Akash Agrawal, 5 years ago

Type: Cleanup/optimizationNew feature

comment:2 by Mariusz Felisiak, 5 years ago

Component: UtilitiesDocumentation
Easy pickings: set
Summary: Add support for altering UniqueConstraint in SchemaEditorDocument SchemaEditor.add_constraint()/remove_constraint() methods.
Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization

alter_unique_together() exists for altering Options.unique_together, i.e. a list of lists that must be unique when considered together. It doesn't "alter" unique constraints in reality it will add/remove unique constraints.

SchemaEditor supports add_constraint() and remove_constraint() operations for Meta.constraints manipulation, but it seems that they are undocumented. We should document them.

in reply to:  2 comment:3 by Akash Agrawal, 5 years ago

Replying to felixxm:

alter_unique_together() exists for altering Options.unique_together, i.e. a list of lists that must be unique when considered together. It doesn't "alter" unique constraints in reality it will add/remove unique constraints.

SchemaEditor supports add_constraint() and remove_constraint() operations for Meta.constraints manipulation, but it seems that they are undocumented. We should document them.

So does it mean that to alter a constraint, the old constraint needs to be deleted and the new modified constraint must be added as two separate operations?

Last edited 5 years ago by Akash Agrawal (previous) (diff)

comment:4 by Mariusz Felisiak, 5 years ago

Exactly.

comment:5 by Akash Agrawal, 5 years ago

Owner: changed from nobody to Akash Agrawal
Status: newassigned

in reply to:  2 comment:6 by Akash Agrawal, 5 years ago

Replying to felixxm:

SchemaEditor supports add_constraint() and remove_constraint() operations for Meta.constraints manipulation.

I just went through the code for add constraint and delete constraint in schema editor and the comment in the function says that it adds/deletes a check constraint. What about unique together constraint?

Last edited 5 years ago by Akash Agrawal (previous) (diff)

comment:7 by Mariusz Felisiak, 5 years ago

Good catch, I fixed docstrings in d14fa04ab398e77e6f19b0453af4183b5e4cd14e.

in reply to:  7 comment:8 by Akash Agrawal, 5 years ago

Replying to felixxm:

Good catch, I fixed docstrings in d14fa04ab398e77e6f19b0453af4183b5e4cd14e.

Thanks, shall I update the documentation for schema editor with add and delete constraint methods?

comment:9 by Mariusz Felisiak, 5 years ago

Yes, we should add add_constraint() and remove_constraint() to the documentation.

comment:10 by Akash Agrawal, 5 years ago

Please review my PR for the above ticket and guide me how to fix the failed checks in the PR.

comment:11 by Akash Agrawal, 5 years ago

Has patch: set

comment:12 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In af08a544:

Fixed #30670 -- Doc'd SchemaEditor.add/remove_constraint().

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 8a3a3280:

[2.2.x] Fixed #30670 -- Doc'd SchemaEditor.add/remove_constraint().

Backport of af08a5441585393b287535b9417436b896bd8052 from master

Note: See TracTickets for help on using tickets.
Back to Top