Ticket #8316: db-mysqltypeissue.7.diff
File db-mysqltypeissue.7.diff, 3.3 KB (added by , 16 years ago) |
---|
-
django/db/backends/__init__.py
71 71 interprets_empty_strings_as_nulls = False 72 72 can_use_chunked_reads = True 73 73 uses_savepoints = False 74 keys_need_similar_types = False 74 75 75 76 class BaseDatabaseOperations(object): 76 77 """ -
django/db/backends/mysql/base.py
68 68 class DatabaseFeatures(BaseDatabaseFeatures): 69 69 empty_fetchmany_value = () 70 70 update_can_self_select = False 71 keys_need_similar_types = True 71 72 72 73 class DatabaseOperations(BaseDatabaseOperations): 73 74 def date_extract_sql(self, lookup_type, field_name): -
django/db/models/fields/related.py
729 729 # of the field to which it points. An exception is if the ForeignKey 730 730 # points to an AutoField/PositiveIntegerField/PositiveSmallIntegerField, 731 731 # 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. 732 734 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))): 734 740 return IntegerField().db_type() 735 741 return rel_field.db_type() 736 742 -
tests/regressiontests/model_regress/models.py
32 32 class Event(models.Model): 33 33 when = models.DateTimeField() 34 34 35 class 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 42 class 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 35 49 __test__ = {'API_TESTS': """ 36 50 (NOTE: Part of the regression test here is merely parsing the model 37 51 declaration. The verbose_name, in particular, did not always work.) … … 87 101 datetime.datetime(2000, 1, 1, 13, 1, 1) 88 102 >>> e.get_previous_by_when().when 89 103 datetime.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> 90 112 """ 91 113 }