Commit 4b3fd424 authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #15782 -- Prevented MySQL backend to crash on runserver when db server...

Fixed #15782 -- Prevented MySQL backend to crash on runserver when db server is down. Thanks toofishes for the report and patch.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17868 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 60ceeda9
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -11,11 +11,17 @@ class DatabaseValidation(BaseDatabaseValidation):
          characters if they have a unique index on them.
        """
        from django.db import models
        from MySQLdb import OperationalError
        try:
            db_version = self.connection.get_server_version()
            text_version = '.'.join([str(n) for n in db_version[:3]])
        except OperationalError:
            db_version = None
            text_version = ''
        varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
                models.SlugField)
        if isinstance(f, varchar_fields) and f.max_length > 255:
            if db_version < (5, 0, 3):
            if db_version and db_version < (5, 0, 3):
                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).'
            elif f.unique == True:
                msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
@@ -23,4 +29,4 @@ class DatabaseValidation(BaseDatabaseValidation):
                msg = None

            if msg:
                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': '.'.join([str(n) for n in db_version[:3]])})
                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version})