~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to django/db/backends/mysql/validation.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone, Jakub Wilk, Luke Faraone
  • Date: 2013-05-09 15:10:47 UTC
  • mfrom: (1.1.21) (4.4.27 sid)
  • Revision ID: package-import@ubuntu.com-20130509151047-aqv8d71oj9wvcv8c
Tags: 1.5.1-2
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Luke Faraone ]
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
        db_version = self.connection.get_server_version()
15
11
        varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
16
12
                models.SlugField)
17
 
        if isinstance(f, varchar_fields) and f.max_length > 255:
18
 
            if db_version < (5, 0, 3):
19
 
                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
 
            elif f.unique == True:
21
 
                msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
22
 
            else:
23
 
                msg = None
24
 
 
25
 
            if msg:
26
 
                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': '.'.join([str(n) for n in db_version[:3]])})
 
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__})