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 , 13 years ago) |
---|
-
django/db/backends/mysql/validation.py
11 11 characters if they have a unique index on them. 12 12 """ 13 13 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 = '' 15 21 varchar_fields = (models.CharField, models.CommaSeparatedIntegerField, 16 22 models.SlugField) 17 23 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): 19 25 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).' 20 26 elif f.unique == True: 21 27 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".' … … 23 29 msg = None 24 30 25 31 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})