Ticket #7789: 7789_fields_2.diff
File 7789_fields_2.diff, 2.2 KB (added by , 16 years ago) |
---|
-
db/models/fields/__init__.py
149 149 # mapped to one of the built-in Django field types. In this case, you 150 150 # can implement db_type() instead of get_internal_type() to specify 151 151 # exactly which wacky database column type you want to use. 152 data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_")153 152 try: 153 data = get_creation_module().backend_parameters(self, self.__dict__) 154 except AttributeError: 155 # No backend_parameters provided in backend 156 data = self.__dict__ 157 data = DictWrapper(data, connection.ops.quote_name, "qn_") 158 try: 154 159 return get_creation_module().DATA_TYPES[self.get_internal_type()] % data 155 160 except KeyError: 156 161 return None -
db/backends/mysql/creation.py
5 5 DATA_TYPES = { 6 6 'AutoField': 'integer AUTO_INCREMENT', 7 7 'BooleanField': 'bool', 8 'CharField': 'varchar(%(max_length)s) ',8 'CharField': 'varchar(%(max_length)s) %(binary)s', 9 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', … … 20 20 'PhoneNumberField': 'varchar(20)', 21 21 'PositiveIntegerField': 'integer UNSIGNED', 22 22 'PositiveSmallIntegerField': 'smallint UNSIGNED', 23 'SlugField': 'varchar(%(max_length)s) ',23 'SlugField': 'varchar(%(max_length)s) BINARY', 24 24 'SmallIntegerField': 'smallint', 25 25 'TextField': 'longtext', 26 26 'TimeField': 'time', 27 27 'USStateField': 'varchar(2)', 28 28 } 29 30 31 def backend_parameters(field, field_dict): 32 """ 33 For MySQL a unique CharField has to be created as a BINARY column as 34 database level. 35 """ 36 if field.unique and field.get_internal_type() == 'CharField': 37 return dict(field_dict, binary='BINARY') 38 return dict(field_dict, binary='')