Ticket #18116: 18116-require-mysql-5.0.3-1.diff

File 18116-require-mysql-5.0.3-1.diff, 6.2 KB (added by Ramiro Morales, 12 years ago)
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    a b  
    1515    from django.core.exceptions import ImproperlyConfigured
    1616    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
    1717
     18from django.utils.functional import cached_property
     19
    1820# We want version (1, 2, 1, 'final', 2) or later. We can't just use
    1921# lexicographic ordering in this check because then (1, 2, 1, 'gamma')
    2022# inadvertently passes the version test.
    2123version = Database.version_info
    22 if (version < (1,2,1) or (version[:3] == (1, 2, 1) and
     24if (version < (1, 2, 1) or (version[:3] == (1, 2, 1) and
    2325        (len(version) < 5 or version[3] != 'final' or version[4] < 2))):
    2426    from django.core.exceptions import ImproperlyConfigured
    2527    raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__)
     
    163165    supports_timezones = False
    164166    requires_explicit_null_ordering_when_grouping = True
    165167    allows_primary_key_0 = False
     168    uses_savepoints = True
    166169
    167170    def __init__(self, connection):
    168171        super(DatabaseFeatures, self).__init__(connection)
     
    387390            self.connection = Database.connect(**kwargs)
    388391            self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
    389392            self.connection.encoders[SafeString] = self.connection.encoders[str]
    390             self.features.uses_savepoints = \
    391                 self.get_server_version() >= (5, 0, 3)
    392393            connection_created.send(sender=self.__class__, connection=self)
    393394        cursor = self.connection.cursor()
    394395        if new_connection:
     
    405406        except Database.NotSupportedError:
    406407            pass
    407408
    408     def get_server_version(self):
     409    @cached_property
     410    def mysql_version(self):
    409411        if not self.server_version:
    410412            if not self._valid_connection():
    411                 self.cursor()
     413                self.cursor().close()
    412414            m = server_version_re.match(self.connection.get_server_info())
    413415            if not m:
    414416                raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
  • django/db/backends/mysql/validation.py

    diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py
    a b  
    33class DatabaseValidation(BaseDatabaseValidation):
    44    def validate_field(self, errors, opts, f):
    55        """
    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.
    129        """
    1310        from django.db import models
    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 = ''
    2111        varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
    2212                models.SlugField)
    2313        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:
     14            if f.unique == True:
    2715                msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
    2816            else:
    2917                msg = None
    3018
    3119            if msg:
    32                 errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version})
     20                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__})
  • docs/ref/databases.txt

    diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt
    a b  
    122122MySQL notes
    123123===========
    124124
    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.
     125Version support
     126---------------
    129127
    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 ---------
     128Django supports MySQL 5.0.3 and higher.
    141129
    142130`MySQL 5.0`_ adds the ``information_schema`` database, which contains detailed
    143131data 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
     137Django expects the database to support transactions, referential integrity, and
     138Unicode (UTF-8 encoding).
    146139
    147140.. _MySQL: http://www.mysql.com/
    148 .. _MySQL 4.1: http://dev.mysql.com/doc/refman/4.1/en/index.html
    149141.. _MySQL 5.0: http://dev.mysql.com/doc/refman/5.0/en/index.html
    150142
    151143Storage engines
     
    381373:class:`~django.db.models.SlugField` and
    382374:class:`~django.db.models.CommaSeparatedIntegerField`.
    383375
    384 Furthermore, if you are using a version of MySQL prior to 5.0.3, all of those
    385 column types have a maximum length restriction of 255 characters, regardless
    386 of whether ``unique=True`` is specified or not.
    387 
    388376DateTime fields
    389377~~~~~~~~~~~~~~~
    390378
Back to Top