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
This commit is contained in:
Claude Paroz 2012-04-02 20:29:50 +00:00
parent 60ceeda9d5
commit 4b3fd424f4
1 changed files with 9 additions and 3 deletions

View File

@ -11,11 +11,17 @@ class DatabaseValidation(BaseDatabaseValidation):
characters if they have a unique index on them.
"""
from django.db import models
db_version = self.connection.get_server_version()
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})