Ticket #9431: untitled 21.diff

File untitled 21.diff, 1.7 KB (added by Adam Nelson, 16 years ago)

django/django/db/backends/mysql/validation.py

  • Users/adam/Development/django/django/db/backends/mysql/validation.py

     
    22
    33class DatabaseValidation(BaseDatabaseValidation):
    44    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        """"
    611        from django.db import models
    712        from django.db import connection
    813        db_version = connection.get_server_version()
     
    1015            errors.add(opts,
    1116                '"%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).' %
    1217                (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]])))
    1322   
     23 No newline at end of file
Back to Top