Ticket #18116: 18116-require-mysql-5.0.3-2.diff
File 18116-require-mysql-5.0.3-2.diff, 8.3 KB (added by , 13 years ago) |
---|
-
django/db/backends/mysql/base.py
diff -r 99b02d130047 django/db/backends/mysql/base.py
a b 15 15 from django.core.exceptions import ImproperlyConfigured 16 16 raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) 17 17 18 from django.utils.functional import cached_property 19 18 20 # We want version (1, 2, 1, 'final', 2) or later. We can't just use 19 21 # lexicographic ordering in this check because then (1, 2, 1, 'gamma') 20 22 # inadvertently passes the version test. 21 23 version = Database.version_info 22 if (version < (1, 2,1) or (version[:3] == (1, 2, 1) and24 if (version < (1, 2, 1) or (version[:3] == (1, 2, 1) and 23 25 (len(version) < 5 or version[3] != 'final' or version[4] < 2))): 24 26 from django.core.exceptions import ImproperlyConfigured 25 27 raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__) … … 163 165 supports_timezones = False 164 166 requires_explicit_null_ordering_when_grouping = True 165 167 allows_primary_key_0 = False 168 uses_savepoints = True 166 169 167 170 def __init__(self, connection): 168 171 super(DatabaseFeatures, self).__init__(connection) … … 387 390 self.connection = Database.connect(**kwargs) 388 391 self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode] 389 392 self.connection.encoders[SafeString] = self.connection.encoders[str] 390 self.features.uses_savepoints = \391 self.get_server_version() >= (5, 0, 3)392 393 connection_created.send(sender=self.__class__, connection=self) 393 394 cursor = self.connection.cursor() 394 395 if new_connection: … … 405 406 except Database.NotSupportedError: 406 407 pass 407 408 408 def get_server_version(self): 409 @cached_property 410 def mysql_version(self): 409 411 if not self.server_version: 410 412 if not self._valid_connection(): 411 self.cursor() 413 self.cursor().close() 412 414 m = server_version_re.match(self.connection.get_server_info()) 413 415 if not m: 414 416 raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info()) -
django/db/backends/mysql/introspection.py
diff -r 99b02d130047 django/db/backends/mysql/introspection.py
a b 65 65 key columns in given table. 66 66 """ 67 67 key_columns = [] 68 try: 69 cursor.execute(""" 70 SELECT column_name, referenced_table_name, referenced_column_name 71 FROM information_schema.key_column_usage 72 WHERE table_name = %s 73 AND table_schema = DATABASE() 74 AND referenced_table_name IS NOT NULL 75 AND referenced_column_name IS NOT NULL""", [table_name]) 76 key_columns.extend(cursor.fetchall()) 77 except (ProgrammingError, OperationalError): 78 # Fall back to "SHOW CREATE TABLE", for previous MySQL versions. 79 # Go through all constraints and save the equal matches. 80 cursor.execute("SHOW CREATE TABLE %s" % self.connection.ops.quote_name(table_name)) 81 for row in cursor.fetchall(): 82 pos = 0 83 while True: 84 match = foreign_key_re.search(row[1], pos) 85 if match == None: 86 break 87 pos = match.end() 88 key_columns.append(match.groups()) 68 cursor.execute(""" 69 SELECT column_name, referenced_table_name, referenced_column_name 70 FROM information_schema.key_column_usage 71 WHERE table_name = %s 72 AND table_schema = DATABASE() 73 AND referenced_table_name IS NOT NULL 74 AND referenced_column_name IS NOT NULL""", [table_name]) 75 key_columns.extend(cursor.fetchall()) 89 76 return key_columns 90 77 91 78 def get_primary_key_column(self, cursor, table_name): -
django/db/backends/mysql/validation.py
diff -r 99b02d130047 django/db/backends/mysql/validation.py
a b 3 3 class DatabaseValidation(BaseDatabaseValidation): 4 4 def validate_field(self, errors, opts, f): 5 5 """ 6 There are some field length restrictions for MySQL: 7 8 - Prior to version 5.0.3, character fields could not exceed 255 9 characters in length. 10 - No character (varchar) fields can have a length exceeding 255 11 characters if they have a unique index on them. 6 MySQL has the following field length restriction: 7 No character (varchar) fields can have a length exceeding 255 8 characters if they have a unique index on them. 12 9 """ 13 10 from django.db import models 14 from MySQLdb import OperationalError15 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 = None20 text_version = ''21 11 varchar_fields = (models.CharField, models.CommaSeparatedIntegerField, 22 12 models.SlugField) 23 if isinstance(f, varchar_fields) and f.max_length > 255: 24 if db_version and db_version < (5, 0, 3): 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).' 26 elif f.unique == True: 27 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".' 28 else: 29 msg = None 30 31 if msg: 32 errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version}) 13 if isinstance(f, varchar_fields) and f.max_length > 255 and f.unique: 14 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".' 15 errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__}) -
docs/ref/databases.txt
diff -r 99b02d130047 docs/ref/databases.txt
a b 122 122 MySQL notes 123 123 =========== 124 124 125 Django expects the database to support transactions, referential integrity, and 126 Unicode (UTF-8 encoding). Fortunately, MySQL_ has all these features as 127 available as far back as 3.23. While it may be possible to use 3.23 or 4.0, 128 you'll probably have less trouble if you use 4.1 or 5.0. 125 Version support 126 --------------- 129 127 130 MySQL 4.1 131 --------- 132 133 `MySQL 4.1`_ has greatly improved support for character sets. It is possible to 134 set different default character sets on the database, table, and column. 135 Previous versions have only a server-wide character set setting. It's also the 136 first version where the character set can be changed on the fly. 4.1 also has 137 support for views, but Django currently doesn't use views. 138 139 MySQL 5.0 140 --------- 128 Django supports MySQL 5.0.3 and higher. 141 129 142 130 `MySQL 5.0`_ adds the ``information_schema`` database, which contains detailed 143 131 data on all database schema. Django's ``inspectdb`` feature uses this 144 ``information_schema`` if it's available. 5.0 also has support for stored 145 procedures, but Django currently doesn't use stored procedures. 132 ``information_schema`` if it's available. 133 134 .. versionchanged:: 1.5 135 The minimum version requirement of MySQL 5.0.3 was set in Django 1.5. 136 137 Django expects the database to support transactions, referential integrity, and 138 Unicode (UTF-8 encoding). 146 139 147 140 .. _MySQL: http://www.mysql.com/ 148 .. _MySQL 4.1: http://dev.mysql.com/doc/refman/4.1/en/index.html149 141 .. _MySQL 5.0: http://dev.mysql.com/doc/refman/5.0/en/index.html 150 142 151 143 Storage engines … … 381 373 :class:`~django.db.models.SlugField` and 382 374 :class:`~django.db.models.CommaSeparatedIntegerField`. 383 375 384 Furthermore, if you are using a version of MySQL prior to 5.0.3, all of those385 column types have a maximum length restriction of 255 characters, regardless386 of whether ``unique=True`` is specified or not.387 388 376 DateTime fields 389 377 ~~~~~~~~~~~~~~~ 390 378