Django unique_together doesn't work with ForeignKey=None

前端 未结 3 1342
抹茶落季
抹茶落季 2021-01-05 03:40

I saw some ppl had this problem before me, but on older versions of Django, and I\'m running on 1.2.1.

I have a model that looks like:

class Category         


        
3条回答
  •  清酒与你
    2021-01-05 04:18

    Unfortunately, for those of us using PostgreSQL as our backend database engine, there will never have a fix for this issue:

    "Currently, only B-tree indexes can be declared unique.

    When an index is declared unique, multiple table rows with equal indexed values are not allowed. Null values are not considered equal. A multicolumn unique index will only reject cases where all indexed columns are equal in multiple rows.

    PostgreSQL automatically creates a unique index when a unique constraint or primary key is defined for a table. The index covers the columns that make up the primary key or unique constraint (a multicolumn index, if appropriate), and is the mechanism that enforces the constraint."

    Source: https://www.postgresql.org/docs/9.0/indexes-unique.html

提交回复
热议问题