#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 , 6 years ago
| Type: | Cleanup/optimization → New feature | 
|---|
follow-ups: 3 6 comment:2 by , 6 years ago
| Component: | Utilities → Documentation | 
|---|---|
| Easy pickings: | set | 
| Summary: | Add support for altering UniqueConstraint in SchemaEditor → Document SchemaEditor.add_constraint()/remove_constraint() methods. | 
| Triage Stage: | Unreviewed → Accepted | 
| Type: | New feature → Cleanup/optimization | 
comment:3 by , 6 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.
SchemaEditorsupportsadd_constraint()andremove_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?
comment:5 by , 6 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
comment:6 by , 6 years ago
Replying to felixxm:
SchemaEditorsupportsadd_constraint()andremove_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?
follow-up: 8 comment:7 by , 6 years ago
Good catch, I fixed docstrings in d14fa04ab398e77e6f19b0453af4183b5e4cd14e.
comment:8 by , 6 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 , 6 years ago
Yes, we should add add_constraint() and remove_constraint() to the documentation.
comment:10 by , 6 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 , 6 years ago
| Has patch: | set | 
|---|
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.SchemaEditorsupportsadd_constraint()andremove_constraint()operations for Meta.constraints manipulation, but it seems that they are undocumented. We should document them.