I accepted this ticket: #34949 (Fails to create unique constraints) – Django describing the behaviour inconsistency between Index and UniqueConstraint and wanted to elicit some discussion here.
tl;dr Index with
include only ignores the option if not supported whereas UniqueConstraint with either
nulls_distinct ignores the whole constraint if not supported.
Should this be a doc update or do we want to bring the behaviour inline?
- UniqueConstraint has long-standing history of not creating the constraint if supplied option is not supported (eg deferrable). Changing behaviour to make only
nulls_distinctoptions be ignore yet creating the constraint would make it internally inconsistent.
- Is changing Index to behave like UniqueConstraint a better option?
- Currently docs state with admonition “Deferrable unique constraints are ignored on MySQL, MariaDB, and SQLite as neither supports them.” yet no such admonition for
include. If we go with doc update then I’d suggest doing that.