Ticket #9431: untitled 21.diff
File untitled 21.diff, 1.7 KB (added by , 16 years ago) |
---|
-
Users/adam/Development/django/django/db/backends/mysql/validation.py
2 2 3 3 class DatabaseValidation(BaseDatabaseValidation): 4 4 def validate_field(self, errors, opts, f): 5 "Prior to MySQL 5.0.3, character fields could not exceed 255 characters" 5 """ 6 Prior to MySQL 5.0.3 (i.e. MySQL 4.x), character fields could not exceed 255 characters 7 On all 5.0 MySQL and earlier, varchar fields cannot have more than 255 characters if the column 8 has a UNIQUE index and the table type is InnoDB. MyISAM has some room for a few more characters 9 but for the sake of portability, that will be ignored. 10 """" 6 11 from django.db import models 7 12 from django.db import connection 8 13 db_version = connection.get_server_version() … … 10 15 errors.add(opts, 11 16 '"%s": %s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % 12 17 (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]]))) 18 if isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255 and f.unique == True: 19 errors.add(opts, 20 '"%s": %s cannot have a "max_length" greater than 255 on a UNIQUE column when you are using MySQL (you are using %s).' % 21 (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]]))) 13 22 23 No newline at end of file