Opened 7 years ago

Last modified 4 weeks ago

#11964 assigned New feature

Add the ability to use database-level CHECK CONSTRAINTS

Reported by: Matthew Schinckel Owned by: Ian Foote
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: check contsraint
Cc: Danilo Bargen, esigra, gam_phon, python@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I mentioned adding database level CHECK CONSTRAINTS in a post on django-developers.

http://groups.google.com/group/django-developers/browse_thread/thread/38937992972c7808

Attached to this ticket is a patch that provides the functionality listed in the first post of this thread. This is not complete: it only allows simple constraints, and is missing a complete test suite.

Attachments (1)

check_constraints.diff (15.8 KB) - added by Matthew Schinckel 7 years ago.
Contains patches against trunk that enable check constraints

Download all attachments as: .zip

Change History (14)

Changed 7 years ago by Matthew Schinckel

Attachment: check_constraints.diff added

Contains patches against trunk that enable check constraints

comment:1 Changed 7 years ago by Russell Keith-Magee

Triage Stage: UnreviewedSomeday/Maybe

If we do this, it should be tied into the model validation framework in some way.

comment:2 Changed 7 years ago by Matthew Schinckel

Agreed. The initial patch was made before the changes with model validation had hit. I will get back to this at some stage.

comment:3 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:4 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 Changed 5 years ago by Danilo Bargen

Cc: Danilo Bargen added

comment:7 Changed 21 months ago by Tim Graham

Patch needs improvement: set

comment:8 Changed 19 months ago by esigra

Cc: esigra added

comment:9 Changed 16 months ago by Tim Graham

Summary: Using database-level CHECK CONSTRAINTSAdd the ability to use database-level CHECK CONSTRAINTS
Triage Stage: Someday/MaybeAccepted
Version: 1.1master

comment:10 Changed 16 months ago by gam_phon

Cc: gam_phon added

comment:11 Changed 7 months ago by Rich Rauenzahn

Could/should this feature request also handle this case of constraint I brought up in this thread?

https://code.djangoproject.com/ticket/11964

Basically unique_together doesn't consider a null value unique per SQL spec -- which makes perfect sense in single column indexes and is extended to multi column indexes.

So if someone wanted (A, B, NULL) to be a unique row there would need to be an index built on the first two columns "where <third column> is null"

These SO articles give a better overview:

http://stackoverflow.com/questions/17510261/django-unique-together-constraint-failure
http://dba.stackexchange.com/questions/9759/postgresql-multi-column-unique-constraint-and-null-values

comment:12 Changed 7 months ago by alexpirine

I would also love this feature.

comment:13 Changed 4 weeks ago by Ian Foote

Cc: python@… added
Owner: changed from nobody to Ian Foote
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top