Ticket #5671: unique.diff

File unique.diff, 4.8 KB (added by Nis Jørgensen <nis@…>, 17 years ago)

Patch doing both of the things mentioned in the article

  • django/db/models/fields/__init__.py

     
    8787        self.name = name
    8888        self.verbose_name = verbose_name
    8989        self.primary_key = primary_key
    90         self.max_length, self.unique = max_length, unique
    91         self.blank, self.null = blank, null
     90        self.max_length = max_length
     91        self.unique = unique or primary_key
     92        self.blank = blank
     93        self.null = null
    9294        # Oracle treats the empty string ('') as null, so coerce the null
    9395        # option whenever '' is a possible value.
    9496        if self.empty_strings_allowed and settings.DATABASE_ENGINE == 'oracle':
     
    98100        self.serialize = serialize
    99101        self.validator_list = validator_list or []
    100102        self.prepopulate_from = prepopulate_from
    101         self.unique_for_date, self.unique_for_month = unique_for_date, unique_for_month
     103        self.unique_for_date = unique_for_date
     104        self.unique_for_month = unique_for_month
    102105        self.unique_for_year = unique_for_year
    103106        self._choices = choices or []
    104107        self.radio_admin = radio_admin
  • django/db/backends/oracle/base.py

     
    2323
    2424class DatabaseFeatures(BaseDatabaseFeatures):
    2525    allows_group_by_ordinal = False
    26     allows_unique_and_pk = False        # Suppress UNIQUE/PK for Oracle (ORA-02259)
    2726    needs_datetime_string_cast = False
    2827    needs_upper_for_iops = True
    2928    supports_tablespaces = True
  • django/db/backends/__init__.py

     
    4141
    4242class BaseDatabaseFeatures(object):
    4343    allows_group_by_ordinal = True
    44     allows_unique_and_pk = True
    4544    autoindexes_primary_keys = True
    4645    needs_datetime_string_cast = True
    4746    needs_upper_for_iops = False
  • django/core/management/commands/createcachetable.py

     
    2121        for f in fields:
    2222            field_output = [qn(f.name), f.db_type()]
    2323            field_output.append("%sNULL" % (not f.null and "NOT " or ""))
    24             if f.unique:
    25                 field_output.append("UNIQUE")
    2624            if f.primary_key:
    2725                field_output.append("PRIMARY KEY")
     26            elif f.unique:
     27                field_output.append("UNIQUE")
    2828            if f.db_index:
    2929                unique = f.unique and "UNIQUE " or ""
    3030                index_output.append("CREATE %sINDEX %s_%s ON %s (%s);" % \
  • django/core/management/sql.py

     
    263263        field_output = [style.SQL_FIELD(qn(f.column)),
    264264            style.SQL_COLTYPE(col_type)]
    265265        field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or '')))
    266         if f.unique and (not f.primary_key or connection.features.allows_unique_and_pk):
    267             field_output.append(style.SQL_KEYWORD('UNIQUE'))
    268266        if f.primary_key:
    269267            field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
    270         if tablespace and connection.features.supports_tablespaces and (f.unique or f.primary_key) and connection.features.autoindexes_primary_keys:
     268        elif f.unique:
     269            field_output.append(style.SQL_KEYWORD('UNIQUE'))
     270        if tablespace and connection.features.supports_tablespaces and f.unique and connection.features.autoindexes_primary_keys:
    271271            # We must specify the index tablespace inline, because we
    272272            # won't be generating a CREATE INDEX statement for this field.
    273273            field_output.append(connection.ops.tablespace_sql(tablespace, inline=True))
     
    427427
    428428    qn = connection.ops.quote_name
    429429    for f in model._meta.fields:
    430         if f.db_index and not ((f.primary_key or f.unique) and connection.features.autoindexes_primary_keys):
     430        if f.db_index and not (f.unique and connection.features.autoindexes_primary_keys):
    431431            unique = f.unique and 'UNIQUE ' or ''
    432432            tablespace = f.db_tablespace or model._meta.db_tablespace
    433433            if tablespace and connection.features.supports_tablespaces:
Back to Top