Ticket #15782: skip-5-0-3-validation-if-db-down.patch

File skip-5-0-3-validation-if-db-down.patch, 1.6 KB (added by Dan McGee, 13 years ago)

Updated to set db_version = None

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

     
    1111          characters if they have a unique index on them.
    1212        """
    1313        from django.db import models
    14         db_version = self.connection.get_server_version()
     14        from MySQLdb import OperationalError
     15        try:
     16            db_version = self.connection.get_server_version()
     17            text_version = '.'.join([str(n) for n in db_version[:3]])
     18        except OperationalError:
     19            db_version = None
     20            text_version = ''
    1521        varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
    1622                models.SlugField)
    1723        if isinstance(f, varchar_fields) and f.max_length > 255:
    18             if db_version < (5, 0, 3):
     24            if db_version and db_version < (5, 0, 3):
    1925                msg = '"%(name)s": %(cls)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 %(version)s).'
    2026            elif f.unique == True:
    2127                msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
     
    2329                msg = None
    2430
    2531            if msg:
    26                 errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': '.'.join([str(n) for n in db_version[:3]])})
     32                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version})
Back to Top