Ticket #8316: db-mysqltypeissue.4.diff

File db-mysqltypeissue.4.diff, 5.9 KB (added by Julian Bez, 16 years ago)

v4, effectively handling that as a special MySQL case

  • django/db/backends/__init__.py

     
    7171    interprets_empty_strings_as_nulls = False
    7272    can_use_chunked_reads = True
    7373    uses_savepoints = False
     74    keys_need_similar_types = False
    7475
    7576class BaseDatabaseOperations(object):
    7677    """
  • django/db/backends/mysql/base.py

     
    8080class DatabaseFeatures(BaseDatabaseFeatures):
    8181    empty_fetchmany_value = ()
    8282    update_can_self_select = False
     83    keys_need_similar_types = True
    8384
    8485class DatabaseOperations(BaseDatabaseOperations):
    8586    def date_extract_sql(self, lookup_type, field_name):
  • django/db/backends/mysql/creation.py

     
    1919        'FloatField':        'double precision',
    2020        'IntegerField':      'integer',
    2121        'IPAddressField':    'char(15)',
     22        'KeyField':          'integer',
    2223        'NullBooleanField':  'bool',
    23         'OneToOneField':     'integer',
    2424        'PhoneNumberField':  'varchar(20)',
    2525        'PositiveIntegerField': 'integer UNSIGNED',
    2626        'PositiveSmallIntegerField': 'smallint UNSIGNED',
  • django/db/backends/oracle/creation.py

     
    2828        'FloatField':                   'DOUBLE PRECISION',
    2929        'IntegerField':                 'NUMBER(11)',
    3030        'IPAddressField':               'VARCHAR2(15)',
     31        'KeyField':                     'NUMBER(11)',
    3132        'NullBooleanField':             'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))',
    32         'OneToOneField':                'NUMBER(11)',
    3333        'PhoneNumberField':             'VARCHAR2(20)',
    3434        'PositiveIntegerField':         'NUMBER(11) CHECK (%(qn_column)s >= 0)',
    3535        'PositiveSmallIntegerField':    'NUMBER(11) CHECK (%(qn_column)s >= 0)',
  • django/db/backends/postgresql/creation.py

     
    1919        'FloatField':        'double precision',
    2020        'IntegerField':      'integer',
    2121        'IPAddressField':    'inet',
     22        'KeyField':          'integer',
    2223        'NullBooleanField':  'boolean',
    23         'OneToOneField':     'integer',
    2424        'PhoneNumberField':  'varchar(20)',
    2525        'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
    2626        'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
  • django/db/backends/sqlite3/creation.py

     
    2020        'FloatField':                   'real',
    2121        'IntegerField':                 'integer',
    2222        'IPAddressField':               'char(15)',
     23        'KeyField':                     'integer',
    2324        'NullBooleanField':             'bool',
    24         'OneToOneField':                'integer',
    2525        'PhoneNumberField':             'varchar(20)',
    2626        'PositiveIntegerField':         'integer unsigned',
    2727        'PositiveSmallIntegerField':    'smallint unsigned',
  • django/db/models/fields/__init__.py

     
    808808        defaults.update(kwargs)
    809809        return super(IPAddressField, self).formfield(**defaults)
    810810
     811class KeyField(IntegerField):
     812    pass
     813
    811814class NullBooleanField(Field):
    812815    empty_strings_allowed = False
    813816    def __init__(self, *args, **kwargs):
  • django/db/models/fields/related.py

     
    11from django.db import connection, transaction
    22from django.db.models import signals, get_model
    3 from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist
     3from django.db.models.fields import AutoField, Field, KeyField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist
    44from django.db.models.related import RelatedObject
    55from django.db.models.query import QuerySet
    66from django.db.models.query_utils import QueryWrapper
     
    713713        # points to an AutoField/PositiveIntegerField/PositiveSmallIntegerField,
    714714        # in which case the column type is simply that of an IntegerField.
    715715        rel_field = self.rel.get_related_field()
    716         if isinstance(rel_field, (AutoField, PositiveIntegerField, PositiveSmallIntegerField)):
    717             return IntegerField().db_type()
     716        if isinstance(rel_field, AutoField) \
     717            or (not connection.features.keys_need_similar_types and
     718                isinstance(rel_field, (AutoField,
     719                                       PositiveIntegerField,
     720                                       PositiveSmallIntegerField))):
     721            return KeyField().db_type()
    718722        return rel_field.db_type()
    719723
    720724class OneToOneField(ForeignKey):
Back to Top