Ticket #8316: db-mysqltypeissue.7.diff

File db-mysqltypeissue.7.diff, 3.3 KB (added by julianb, 7 years ago)
  • 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

     
    6868class DatabaseFeatures(BaseDatabaseFeatures):
    6969    empty_fetchmany_value = ()
    7070    update_can_self_select = False
     71    keys_need_similar_types = True
    7172
    7273class DatabaseOperations(BaseDatabaseOperations):
    7374    def date_extract_sql(self, lookup_type, field_name):
  • django/db/models/fields/related.py

     
    729729        # of the field to which it points. An exception is if the ForeignKey
    730730        # points to an AutoField/PositiveIntegerField/PositiveSmallIntegerField,
    731731        # in which case the column type is simply that of an IntegerField.
     732        # If the database needs similar types for key fields however, the only
     733        # thing we can do is making AutoField an IntegerField.
    732734        rel_field = self.rel.get_related_field()
    733         if isinstance(rel_field, (AutoField, PositiveIntegerField, PositiveSmallIntegerField)):
     735        if isinstance(rel_field, AutoField) \
     736            or (not connection.features.keys_need_similar_types and
     737                isinstance(rel_field, (AutoField,
     738                                       PositiveIntegerField,
     739                                       PositiveSmallIntegerField))):
    734740            return IntegerField().db_type()
    735741        return rel_field.db_type()
    736742
  • tests/regressiontests/model_regress/models.py

     
    3232class Event(models.Model):
    3333    when = models.DateTimeField()
    3434
     35class Department(models.Model):
     36    id = models.PositiveIntegerField(primary_key=True)
     37    name = models.CharField(max_length=200)
     38
     39    def __unicode__(self):
     40        return self.name
     41   
     42class Worker(models.Model):
     43    department = models.ForeignKey(Department)
     44    name = models.CharField(max_length=200)
     45
     46    def __unicode__(self):
     47        return self.name
     48
    3549__test__ = {'API_TESTS': """
    3650(NOTE: Part of the regression test here is merely parsing the model
    3751declaration. The verbose_name, in particular, did not always work.)
     
    87101datetime.datetime(2000, 1, 1, 13, 1, 1)
    88102>>> e.get_previous_by_when().when
    89103datetime.datetime(2000, 1, 1, 6, 1, 1)
     104
     105# Check Department and Worker
     106>>> d = Department(id=10, name='IT')
     107>>> d.save()
     108>>> w = Worker(department=d, name='Full-time')
     109>>> w.save()
     110>>> w
     111<Worker: Full-time>
    90112"""
    91113}
Back to Top