Ticket #2188: Option 2.diff
File Option 2.diff, 3.2 KB (added by , 18 years ago) |
---|
-
core/management.py
809 809 validates all models of all installed apps. Writes errors, if any, to outfile. 810 810 Returns number of errors. 811 811 """ 812 from django.db import models 812 from django.db import models, connection 813 813 from django.db.models.fields.related import RelatedObject 814 from django.conf import settings 814 815 815 816 e = ModelErrorCollection(outfile) 816 817 for cls in models.get_models(app): … … 846 847 if f.db_index not in (None, True, False): 847 848 e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name) 848 849 850 # Check maxlength < 255 for older MySQL varchar fields 851 if settings.DATABASE_ENGINE == 'mysql': 852 db_version = connection.get_server_version() 853 if db_version < (5, 0, 3): 854 if isinstance(f, models.CharField) and f.maxlength > 255: 855 e.add(opts, '"%s": CharFields cannot have a "maxlength" greater than 255 when you are using a version of MySQL older than 5.0.3; you are using %s.' % (f.name, '.'.join(str(n) for n in db_version[:3]))) 856 if isinstance(f, models.CommaSeparatedIntegerField) and f.maxlength > 255: 857 e.add(opts, '"%s": CommaSeparatedIntegerField cannot have a "maxlength" greater than 255 when you are using a version of MySQL older than 5.0.3; you are using %s.' % (f.name, '.'.join(str(n) for n in db_version[:3]))) 858 if isinstance(f, models.SlugField) and f.maxlength > 255: 859 e.add(opts, '"%s": SlugField cannot have a "maxlength" greater than 255 when you are using a version of MySQL older than 5.0.3; you are using %s.' % (f.name, '.'.join(str(n) for n in db_version[:3]))) 860 849 861 # Check to see if the related field will clash with any 850 862 # existing fields, m2m fields, m2m related objects or related objects 851 863 if f.rel: -
db/backends/mysql/base.py
12 12 raise ImproperlyConfigured, "Error loading MySQLdb module: %s" % e 13 13 from MySQLdb.converters import conversions 14 14 from MySQLdb.constants import FIELD_TYPE 15 import types 15 import types, re 16 16 17 17 DatabaseError = Database.DatabaseError 18 18 … … 61 61 def __init__(self): 62 62 self.connection = None 63 63 self.queries = [] 64 self.server_version = None 64 65 65 66 def _valid_connection(self): 66 67 if self.connection is not None: … … 95 96 return util.CursorDebugWrapper(MysqlDebugWrapper(cursor), self) 96 97 return cursor 97 98 99 def get_server_version(self): 100 if not self.server_version: 101 if not self._valid_connection(): 102 self.cursor() 103 version = re.compile('[\.-]').split(self.connection.get_server_info()) 104 self.server_version = tuple(int(x) for x in version[:3]) + tuple(version[3:]) 105 return self.server_version 106 98 107 def _commit(self): 99 108 self.connection.commit() 100 109